电子邮件与EWS绑定时未检测到.MSG文件

时间:2012-06-28 09:37:23

标签: .net exchangewebservices email-attachments

我正在使用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);
            }
        }
    }
}

1 个答案:

答案 0 :(得分: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.
}