将原始字符串转换为 MimeMessage

Convert Raw string to MimeMessage

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

从 gmail 获取原始邮件的代码:

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
  }

如有任何帮助,我们将不胜感激。谢谢

很简单,感谢 Rufo 爵士的点子!

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

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