如何从资源文件夹中添加图像作为附件并嵌入到C#中的Outlook邮件正文中 [英] How to add images from resources folder as attachment and embed into outlook mail body in C#

查看:156
本文介绍了如何从资源文件夹中添加图像作为附件并嵌入到C#中的Outlook邮件正文中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Visual Studio项目的Resources文件夹中存储了一些图像,我必须加载它们并在Outlook邮件正文中显示.这是代码:

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:

Bitmap b = new Bitmap(Properties.Resources.MyImage);
ImageConverter ic = new ImageConverter();
Byte[] ba = (Byte[])ic.ConvertTo(b, typeof(Byte[]));
MemoryStream logo = new MemoryStream(ba);

LinkedResource companyImage = new LinkedResource(logo);
companyImage.ContentId = "companyLogo";
mailitem.HTMLBody += "<img src=\"cid:companyLogo\">";

但是,它不能显示在邮件正文上,而只能显示带有红色x的空白框".你能给我一些想法吗?

However, it cannot display on the mail body but a ‘empty box with red x’. Can you give me some ideas?

推荐答案

创建附件并设置PR_ATTACH_CONTENT_ID属性(DASL名称为" http://schemas.microsoft.com/mapi/proptag/0x3712001F ),使用Attachment.PropertyAccessor.

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

您的HTML正文(MailItem.HTMLBody属性)随后将需要通过cid引用该图像附件:

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

img src ="cid:xyz"

img src="cid:xyz"

其中xyz是PR_ATTACH_CONTENT_ID属性的值.

where xyz is the value of the PR_ATTACH_CONTENT_ID property.

使用 OutlookSpy 查看现有邮件(单击IMessage按钮).

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>"

这篇关于如何从资源文件夹中添加图像作为附件并嵌入到C#中的Outlook邮件正文中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆