How to add images from resources folder as attachment and embed into outlook mail body in C#

前端 未结 2 927
难免孤独
难免孤独 2021-01-28 22:44

I have a couple of images stored in visual studio project Resources folder, and I have to load them and display on the outlook mail body. Here it is the code:

B         


        
2条回答
  •  佛祖请我去吃肉
    2021-01-28 23:13

    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 = "Test image "
    

提交回复
热议问题