在电子邮件正文中嵌入图像
我正在为 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>";
}
}
}
但这不显示图像。请帮忙。
提前致谢。
I am creating an add in for outlook 2007, and what i am trying to do is embed an image to a new email. I cannot get the embedding of the image to work, please help. My code is as follows:
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>";
}
}
}
but this is not displaying the image. Please help.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然我没有直接使用 Outlook 组件,但您需要将图像嵌入到邮件中。您在上面的代码中所做的就是创建一个引用本地硬盘上的图像的字符串。
在我的世界中,我使用 .NET 邮件组件,所以对此持保留态度,但概念应该转移。我做了这样的事情:
此外,在创建 HTML 消息时,包含纯文本版本被认为是很好的做法。
While I haven't used the Outlook components directly, you're going to need to embed the image in the mail. All you are doing in the code above is creating a string that references an image on your local hard drive.
In my world, I iuse the .NET mail components, so take this with a grain of salt, but the concepts should transfer. I do something like this:
Also, when creating HTML Messages it is considered good practice to include a plain text version.