将Raw字符串转换为MimeMessage

时间:2017-11-14 01:08:22

标签: c# mime-message rawstring

我想将Gmail原始邮件转换为Mimekit.MimeMessage。可以将MimeMessage转换为Raw字符串但不能反转它。

从gmail获取Raw消息的代码:

var emailInfoReq = service.Users.Messages.Get("me", email.Id);
emailInfoReq.Format = UsersResource.MessagesResource.GetRequest.FormatEnum.Raw; 
var emailInfoResponse = emailInfoReq.Execute();
if (emailInfoResponse != null)
  {                        
    var message = emailInfoResponse.Raw;
    //string Msg = DecodeBase64String(message);
    //byte[] Msg = Base64UrlDecode(message);
    MimeKit.MimeMessage Message1 = new MimeKit.MimeMessage();
    // MimeMessage not taking string as well as byte[] input
  }

任何帮助将不胜感激。感谢。

1 个答案:

答案 0 :(得分:2)

很简单,感谢Rufo爵士的想法!

如果有人想要发布它:将byte []转换为内存流并将其加载到MimeMessage中:

 var message = emailInfoResponse.Raw;
 byte[] Msg = Base64UrlDecode(message);
 MemoryStream mm = new MemoryStream(Msg);
 MimeKit.MimeMessage Message1  = MimeKit.MimeMessage.Load(mm);