繁体   English   中英

从电子邮件中获取附件

[英]Get attachments from E-mail

我正在尝试从 MimeMessage 获取附件。

我做到了这一点:

using (Stream ms = Utils.GenerateStreamFromString(mail.Rfc822Content))
{
    MimeMessage mimeMessage = MimeMessage.Load(ms);
    // collect our list of attachments
    foreach (MimeEntity attachment in mimeMessage.Attachments)
    {
        if (!fileexists)
        {
            using (FileStream file = new FileStream(System.IO.Path.Combine(System.IO.Path.Combine(docMap), bijlageNaam), FileMode.Create, FileAccess.Write))
            {
                ms.Position = 0;
                ms.CopyTo(file);
                file.Flush();
            }
         }
     }
 }

但问题是,现在它明显地写入了 fullContent,因为我正在使用ms.CopyTo(file) ,这不是我想要的。

我正在尝试获取附加到 email 的附件并将其写入文件。

我通过using (var iter = new MimeIterator(mimeMessage))替换foreach解决了我的问题

并开始使用while(item.MoveNext())循环

thanks to that I had acces to the MimePart wich I was able to get the Stream of and I placed that stream into another using (stream stream = part.content.stream) and used that stream to stream.CopyTo(file)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM