【发布时间】:2013-09-08 18:18:51
【问题描述】:
我有以下电子邮件。
运行以下代码后
string pattern = "<img src=\"cid.*?</span></p>|Inline image 1.*?</FONT>";
Outlook.Selection mySelection = Globals.ThisAddIn.Application.ActiveExplorer().Selection;
Outlook.MailItem mailitem = null;
foreach (Object obj in mySelection)
{
if (obj is Outlook.MailItem)
{
mailitem = (Outlook.MailItem)obj;
string body = mailitem.HTMLBody;
Regex reg = new Regex(pattern, RegexOptions.Compiled | RegexOptions.Multiline|RegexOptions.Singleline);
MatchCollection matchs = reg.Matches(body);
foreach(Match match in matchs)
{
string a = match.Groups[0].Value;
mailitem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
mailitem.Body = body.Replace(a, string.Empty);
mailitem.Save();
}
//mailitem.BodyFormat = Outlook.OlBodyFormat.olFormatPlain;
}
}
我在 Outlook 中收到以下电子邮件。
正文在浏览器中有效。这意味着当我将正文文本保存在简单的 html 文件中时,它可以正常工作并显示原始消息。
【问题讨论】:
标签: c#-4.0 html-email outlook-2010