问题
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