【问题标题】:Images in email is showing as attachment in Hotmail or Gmail电子邮件中的图像在 Hotmail 或 Gmail 中显示为附件
【发布时间】:2023-03-10 04:39:02
【问题描述】:

我正在使用 Microsoft.Office.Interop.Outlook.MailItem 发送电子邮件,它是一个 html 电子邮件,正文中有一些图像,我正在将图像作为附件发送

mailItem.Attachments.Add(path + "Header.png", (int)OlAttachmentType.olByValue, 1, "Header");

然后设置body

string body=”<img src="cid:{0}" width="627" height="125" alt="Header">”
mailItem.BodyFormat = OlBodyFormat.olFormatHTML;                
mailItem.HTMLBody = string.Format(body, "Header.png") ;

在 MS Outlook 中一切正常,但图像在 Hotmail(outlook.com) 和 Gmail 中显示为附件,但在 MS Outlook 中,图像显示在正文中应该显示的位置

如果我为我的图像设置 cid(例如域名),我会搜索并找到类似的解决方案。 Header.png@somedomain.com 然后它会起作用,但是当我为附件设置这种类型的名称时,它不起作用并且会出现恶意附件的警告

请推荐

【问题讨论】:

    标签: image email outlook


    【解决方案1】:

    您正在为标头指定 cid 属性,但您从未设置 Content-ID MIME 标头。要在消息转换为 MIME 时设置它,您需要使用 Attachment.PropertyAccessor.SetProperty 设置 PR_ATTACH_CONTENT_ID MAPI 属性(DASL 名称“http://schemas.microsoft.com/mapi/proptag/0x3712001F”)。

    【讨论】:

    • 感谢您的回复,但我尝试了以下代码,但问题仍然没有解决,或者我没有得到正确的语法Attachment a=mailItem.Attachments.Add(path + "Header.png", (int)OlAttachmentType.olByValue, 1, "Header"); a.PropertyAccessor.SetProperty(@"http://schemas.microsoft.com/mapi/proptag/0x3712001F", "Header.png@somedomain.com"); a.PropertyAccessor.SetProperty(@"http://schemas.microsoft.com/mapi/proptag/0x3712001F", "Header.png");
    • 我使用下面的代码mailItem.Attachments[counter - 1].PropertyAccessor.SetProperty( "http://schemas.microsoft.com/mapi/proptag/0x3712001F", "header.png");设置了属性但是问题还是没有解决,
    • 如果您单击 IMessage,您是否看到 OutlookSpy (dimastr.com/outspy) 中的 PR_ATTACH_CONTENT_ID 属性设置正确,请转到 GetAttachmentTable 选项卡并打开附件。您的 HTML 是否正确?
    【解决方案2】:

    这是一个您可以嵌入的图像,它将嵌入到 Hotmail 和 Gmail 中: 此代码在 python 3.9.1 中。

    import win32com.client
    outlook = win32com.client.Dispatch("outlook.application")
    mail = outlook.CreateItem(0)
    attachment = mail.Attachments.Add(embedImgPath) 
    attachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F","MyId1")
    mail.HTMLBody = f"<html><body> {htmlbody} <br> <img src="" cid:MyId1""> </body></html>"
    mail.send()
    

    【讨论】:

      猜你喜欢
      • 2019-03-14
      • 1970-01-01
      • 1970-01-01
      • 2015-09-29
      • 1970-01-01
      • 1970-01-01
      • 2011-05-01
      • 2017-06-11
      • 1970-01-01
      相关资源
      最近更新 更多