VBA to create Outlook message of Content-Type: multipart/related?

和自甴很熟 提交于 2020-01-14 05:29:09

问题


I'm trying to use VBA to create an html email message with embedded graphics. My research indicates that I need to set my content-type to multipart/related, add the graphics as parts of the message, specify a content identifier (CID) for each graphic, then set each graphic's html img tag src attribute to cid:theIdentifierString

Anyone have some good resources on how to achieve this via VBA for scripting Outlook?


回答1:


You do nto directly create MIME messages in Outlook - it is not its native format. It will create MIME message on its onw when it, for example, needs to send through an SMTP server.

That being said, create an attachment and set the PR_ATTACH_CONTENT_ID property (DASL name "http://schemas.microsoft.com/mapi/proptag/0x3712001F") using Attachment.PropertyAccessor.

Your HTML body (MailItem.HTMLBody property) would then need to reference that image attachment through the cid:

img src="cid:xyz"

where xyz is the value of the PR_ATTACH_CONTENT_ID property.

Look at an existing message with OutlookSpy (click IMessage button).

attachment = mailitem.Attachments.Add("c:\temp\MyPicture.jpg")
attachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F", "MyId1")
mailitem.HTMLBody = "<html><body>Test image <img src=""cid:MyId1""></body></html>"


来源:https://stackoverflow.com/questions/41388672/vba-to-create-outlook-message-of-content-type-multipart-related

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!