如何获取附件文件

时间:2013-12-04 14:22:55

标签: c#

在这里,我试图分别收集电子邮件的所有部分,如正文,附件,地址部分,所以我有以下代码。所以我也可以通过使用相同的技术获取附件文件(使用PropertySet类或将RequestedBodyType定义为某些东西)???

有没有办法获取任何类型的附件文件的内容,我不需要太多更改代码?

// Get the Unread mails from the server
SearchFilter itemFilter = new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false);

// get the emails from Inbox folder
FindItemsResults<Item> emails = service.FindItems(WellKnownFolderName.Inbox, itemFilter, view);


foreach (EmailMessage em in emails)
{
    itempropertyset.RequestedBodyType = BodyType.HTML;

    em.Load(itempropertyset);
    em.IsRead = true;
    em.Update(ConflictResolutionMode.AlwaysOverwrite);

    EmailProList.HTMLBody = em.Body.Text;

    itempropertyset.RequestedBodyType = BodyType.Text;
    em.Load(itempropertyset);

    EmailProList.Body = em.Body.Text;
    itempropertyset.RequestedBodyType = 

    EmailProList.ToEmailAddr = em.Sender.Address.ToString(); //JG Changed

    EmailProList.Subject = em.Subject.ToString();

    EmailProList.Type = "Feedback";

}

2 个答案:

答案 0 :(得分:0)

你可以得到这样的附件:

EmailMessage email = item as EmailMessage;

foreach(FileAttachment file in email.FileAttachments)
{
   // Process the attachment
}

答案 1 :(得分:0)

您可以通过这种方式处理附件。

                if (message.HasAttachments && message.Attachments[0] is FileAttachment)
                {
                    FileAttachment fileAttachment = message.Attachments[0] as FileAttachment;
                    Console.WriteLine("email" + fileAttachment.Name);
                    fileAttachment.Load(@"D:\\" + fileAttachment.Name);
                }