0

我正在使用 EWS 1.2 在我的邮箱中搜索带有附件的电子邮件,并将 EmailMessage 对象绑定到 EWS 对象。这工作正常,但没有检测到 .msg 文件(outlook 消息文件):

ItemView mailview = new ItemView (12);
FindItemsResults<Item> resultmail;

resultmail = Service.FindItems(WellKnownFolderName.Inbox, mailview);
foreach (Item item in resultmail.Items)
{                   
    EmailMessage email = EmailMessage.Bind(Service, item.Id,
        new PropertySet(BasePropertySet.FirstClassProperties, 
                        ItemSchema.Attachments));

    if (email.HasAttachments)
    {
        foreach (var attachment in email.Attachments)
        {
            if (attachment is FileAttachment)
            {
                Console.WriteLine("email has : " + email.Attachments.Count
                                + "attachement(s)" + "\n");
                Console.WriteLine("attachment name:" + attachment.Name);
            }
        }
    }
}
4

1 回答 1

1

如果邮件附加到邮件,则不是文件附件,而是项目附件。所以你应该像这样扩展你的代码:

...
if (attachment is FileAttachment) 
{ 
    Console.WriteLine("email has : " + email.Attachments.Count + "attachement(s)" + "\n"); 
    Console.WriteLine("attachment name:" + attachment.Name); 
}
else if (attachment is ItemAttachment)
{
    ItemAttachment itematt = (ItemAttachment) attachment;
    //with itematt.Item you can access the properties of the attachment.
} 
于 2012-07-06T13:42:12.060 回答