使用 MimeKit 时如何获取附件内容?这就是我所拥有的:
var mimeMessage = MimeMessage.Load(@"test.eml");
var attachments = mimeMessage.Attachments.ToList();
foreach (var attachment in attachments)
{
// how do I get the content here (array of bytes or stream)
}
这应该做你需要的:
var mimeMessage = MimeMessage.Load(@"test.eml");
var attachments = mimeMessage.Attachments.ToList();
foreach (var attachment in attachments)
{
using (var memory = new MemoryStream ())
{
if (attachment is MimePart)
((MimePart) attachment).Content.DecodeTo (memory);
else
((MessagePart) attachment).Message.WriteTo (memory);
var bytes = memory.ToArray ();
}
}