1

我正在使用 limilabs 的 Mail.dll 来管理 IMAP 文件夹。有一封带有 eml 文件附件的邮件,所以是一封邮件。它又附带了一个我需要提取的 eml 文件。

所以邮件结构如下:

Email
  |- Attachment: file.eml
                   |- Attachment file2.eml

这是我的代码:

IMail email = new MailBuilder().CreateFromEml(imap.GetMessageByUID(uid));
Console.WriteLine(email.Subject);
// save all attachments to disk
foreach(MimeData mime in email.Attachments)
{
if (uid == 1376)
{
        System.IO.Directory.CreateDirectory(string.Format(@"c:\EMAIL\{0}", uid));
        mime.Save(@"c:\EMAIL\" + uid + "\\" + mime.SafeFileName);
        MimeData help;
        if (mime.ContentType.ToString() == "message/rfc822")
        {
        //i need to cast this attach in a imail
        }
    }
}

如何提取最里面的 eml 文件(上述结构中的 file2.eml)?

4

2 回答 2

2

这个链接,看起来您应该能够执行以下操作:

if (attachment.ContentType == ContentType.MessageRfc822)
{
    string eml = ((MimeText)attachment).Text;
    IMail attachedMessage = new MailBuilder().CreateFromEml(eml);
    // process further
}
于 2013-05-06T14:03:24.610 回答
0

如果您只需要从所有内部消息中提取所有附件,则可以使用IMail.ExtractAttachmentsFromInnerMessages方法:

IMail email = new MailBuilder().CreateFromEml(imap.GetMessageByUID(uid));

ReadOnlyCollection<MimeData> attachments = mail.ExtractAttachmentsFromInnerMessages();
foreach (MimeData mime in attachments)
{
     mime.Save(@"c:\" + mime.SafeFileName);
}
于 2013-12-05T13:49:17.217 回答