【问题标题】:getting image from email从电子邮件中获取图像
【发布时间】:2012-02-29 13:20:34
【问题描述】:

我注意到,当有人复制粘贴电子邮件然后发送它时,图像的“src”值会发生变化。例如,如果原始电子邮件有一个作为附件的图像,其 contentId 是:cid:companlyLogo。然后有人将这封电子邮件复制粘贴到新草稿中并将其发送到此 src 值更改为:src="cid:image001.jpg@01CCF6B1.A4CA2FE0"。

我不知道如何获取此图像并将其保存在 c# 中的图像对象中。我目前正在使用 EWS api 来执行此操作。问题是,由于它是复制粘贴,因此它不再具有作为原始电子邮件的附件。

有人知道如何检索此类电子邮件的图像吗?

【问题讨论】:

    标签: c# exchangewebservices


    【解决方案1】:

    嵌入式图像被 Exchange 视为电子邮件附件。这意味着您可以从Item.Attachments 属性中检索图像。以下示例向您展示如何使用 EWS 托管 API 执行此操作。请注意,EWS 不会加载附件,除非您通过调用 LoadPropertiesForItems 明确告知它。

    您可以通过检查Attachment.IsInline 属性来判断是否嵌入了附件。 EWS 允许您通过调用 FileAttachment.Load 方法加载附件并将其保存到磁盘。

    ExchangeService service = GetService();
    var view = new ItemView(1);
    var searchFilter = new SearchFilter.IsEqualTo(EmailMessageSchema.Subject, "Some subject text");
    var items = service.FindItems(WellKnownFolderName.Inbox, searchFilter, view);
    service.LoadPropertiesForItems(items, new PropertySet(BasePropertySet.FirstClassProperties, EmailMessageSchema.Attachments));
    
    var item = items.ElementAt(0) as EmailMessage;
    
    for (int i = 0; i < item.Attachments.Count; i++)
    {
        var att = item.Attachments[i] as FileAttachment;
        if (att.IsInline && att.ContentType.Contains("image"))
        {
            att.Load(String.Format(@"c:\temp\attachedimage_{0}.jpg", i));
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-14
      • 2020-11-06
      • 1970-01-01
      • 1970-01-01
      • 2010-10-01
      • 1970-01-01
      相关资源
      最近更新 更多