以编程方式在电子邮件中插入Outlook 2010模板不会显示其图片 [英] Inserting an Outlook 2010 template programmatically within an email does not display its pictures

查看:458
本文介绍了以编程方式在电子邮件中插入Outlook 2010模板不会显示其图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


在VS 2013中使用VSTO,我在功能区中创建了一个选项卡,该选项卡仅在创建新邮件,回复或转发时显示。这个新选项卡有一些按钮,可以在打开的邮件中插入以前创建的模板的内容(.oft格式)。


如果模板只包含文本,它会起作用。如果它们包含图片,则不会显示它们。


这是我做的一些代码:

 private void AddTemplateToBody(string templateName)
{
Outlook.Inspector inspector = Globals.ThisAddIn.Application.ActiveInspector();
Outlook.MailItem currentOpenedMail = inspector.CurrentItem as Outlook.MailItem;
尝试
{
Outlook.MailItem templateMail = Globals.ThisAddIn.Application.CreateItemFromTemplate(templatePath + templateName)as Outlook.MailItem;
//在邮件开头添加模板内容
string templateBody = templateMail.HTMLBody;
templateMail.Close(Outlook.OlInspectorClose.olDiscard);
currentOpenedMail.HTMLBody = currentOpenedMail.HTMLBody.Insert(0,templateBody);
}
catch(例外)
{
System.Windows.Forms.MessageBox.Show(" Template" + templatePath + templateName +" not found!") ;

}
}

有任何建议吗?


请注意,我尝试将模板保存为.html文件,并通过以下方法解析其内容,但随后显示图片。


< pre class ="prettyprint"> string templateHTMLContent = System.IO.File.ReadAllText(templatePath + templateName);
currentOpenedMail.HTMLBody = currentOpenedMail.HTMLBody.Insert(0,templateHTMLContent);

提前谢谢你,如果这件事很简单,我道歉:我不在一个开发者,只是一个业余爱好者:)



祝你好运,



Nich




解决方案

Hello Nich,


您是如何在HTML标记中指定图像的?


To添加可以发送给其他人的嵌入图像,您需要指定全局可用的URL(将其上传到任何Web服务器)或将图像嵌入到电子邮件中,并将其cid属性指定为HTML标记中的源。您可能会发现以下
链接有用:


将嵌入图像添加到HTML邮件


cid,inline embedded images


< a href ="https://social.msdn.microsoft.com/Forums/vstudio/en-US/6c063b27-7e8a-4963-ad5f-ce7e5ffb2c64/how-to-embed-image-in-html-body-in- c-into-outlook-mail?forum = vsto"target ="_ blank">如何将c#中的html图像中的图像嵌入到outlook邮件中


Hello everyone,

Using VSTO with VS 2013, I created a tab within the ribbon that is only displayed when creating a new mail, replying or forwarding. This new tab has buttons which insert within the opened mail the content of previously created templates (.oft format).

It works if the templates only contain text. If they contain pictures, they are not being displayed.

Here is the bit of code that I made:

private void AddTemplateToBody(string templateName)
{
	Outlook.Inspector inspector = Globals.ThisAddIn.Application.ActiveInspector();
	Outlook.MailItem currentOpenedMail = inspector.CurrentItem as Outlook.MailItem;
	try
	{
		Outlook.MailItem templateMail = Globals.ThisAddIn.Application.CreateItemFromTemplate(templatePath + templateName) as Outlook.MailItem;
		// add at the beginning of the mail the content of the template
		string templateBody = templateMail.HTMLBody;
		templateMail.Close(Outlook.OlInspectorClose.olDiscard);
		currentOpenedMail.HTMLBody = currentOpenedMail.HTMLBody.Insert(0, templateBody);
	}
	catch (Exception)
	{
		System.Windows.Forms.MessageBox.Show("Template " + templatePath + templateName + " not found!");
		
	}
}

Any suggestion?

Please note that I tried to save the templates as .html files and parse their content via the following method, but the pictures were then displayed randomly.

string templateHTMLContent = System.IO.File.ReadAllText(templatePath + templateName);
currentOpenedMail.HTMLBody = currentOpenedMail.HTMLBody.Insert(0, templateHTMLContent);

Thank you in advance, and my apologies if this something simple: I am in no way a dev, just an hobbyist :)

Best regards,

Nich

解决方案

Hello Nich,

How did you specify images in the HTML markup?

To add an embedded images which can be sent to others you need to specify the globally available URL (upload it to any web server) or embed an image into the email and specify its cid attribute as a source in the HTML markup. You may find the following links helpful:

To add an embedded image to an HTML message

cid, inline embedded images

how to embed image in html body in c# into outlook mail


这篇关于以编程方式在电子邮件中插入Outlook 2010模板不会显示其图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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