我正在为Outlook 2007创建一个插件,我想要做的是将图像嵌入到新的电子邮件中。我无法将图像嵌入工作,请帮忙。我的代码如下:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Outlook.Inspectors inspectors;
inspectors = this.Application.Inspectors;
inspectors.NewInspector +=
new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
{
Outlook.MailItem mailItem = Inspector.CurrentItem as Outlook.MailItem;
if (mailItem != null)
{
if (mailItem.EntryID == null)
{
mailItem.Subject = "This text was added by using code";
mailItem.HTMLBody = "<html><body>this is a <img src=" + @"C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg> embedded picture.</body></html>";
//mailItem.HtmlBody = "<html><body>this is a <img src=\"cid:" + @"C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg" + "\"> embedded picture.</body></html>";
}
}
}
但这不显示图像。请帮忙。
提前致谢。
答案 0 :(得分:0)
虽然我没有直接使用Outlook组件,但您需要将图像嵌入邮件中。您在上面的代码中所做的就是创建一个引用本地硬盘驱动器上的图像的字符串。
在我的世界中,我使用了.NET邮件组件,所以请稍等一下,但概念应该转移。我做这样的事情:
AlternateView htmlView = AlternateView.CreateAlternateViewFromString(model.MessageBody_Html, null, MediaTypeNames.Text.Html);
ImgStream = new MemoryStream(media.MediaData);
linkedImage = new LinkedResource(ImgStream, MediaTypeNames.Image.Jpeg);
linkedImage.ContentId = "img_" + media.MediaID;
linkedImage.TransferEncoding = TransferEncoding.Base64;
htmlView.LinkedResources.Add(linkedImage);
此外,在创建HTML消息时,最好包含纯文本版本。