修改 VSTO Outlook 加载项的 MailItem.Body
本文关键字:MailItem Body 加载项 VSTO Outlook 修改 | 更新日期: 2023-09-27 18:36:47
我们一直试图编辑电子邮件的 html 正文以进行回复和转发。我们有一个自定义表单,我们希望将标题附加到 html 电子邮件正文,具体取决于它是新的电子邮件回复还是转发。您如何让新正文覆盖回复和转发的电子邮件正文。主题工作得很好。
namespace OutlookAddIn
{
public partial class ThisAddIn
{
private Outlook.Inspectors inspectors;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
inspectors = this.Application.Inspectors;
inspectors.NewInspector += new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
// Note: Outlook no longer raises this event. If you have code that
// must run when Outlook shuts down, see http://go.microsoft.com/fwlink/?LinkId=506785
}
void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
{
Outlook.MailItem mailItem = Inspector.CurrentItem as Outlook.MailItem;
if (mailItem != null)
{
if (mailItem.EntryID == null)
{
ClassificationForm formMain = new ClassificationForm();
formMain.ShowDialog();
mailItem.HTMLBody = formMain.GetHTMLBody();
mailItem.Subject = formMain.GetSubject();
}
}
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
}
也尝试了这个,它确实替换了正文的html电子邮件,但它确实打开了两个版本的电子邮件,并且ForwardingMessage.Display(true)不能完全显示电子邮件的编辑版本。
Outlook.MailItem ForwardingMessage = (Outlook.MailItem)this.Application.CreateItem(Outlook.OlItemType.olMailItem);
Outlook.MailItem SelectedMessage = (Outlook.MailItem)this.Application.ActiveExplorer().Selection[1];
if (SelectedMessage != null)
{
if (ForwardingMessage != null)
{
ClassificationForm formMain = new ClassificationForm();
formMain.ShowDialog();
SelectedMessage.HTMLBody = formMain.GetHTMLBody();
SelectedMessage.Subject = formMain.GetSubject();
}
}
我们通过向
电子邮件添加修改数据的窗体区域并使用简单的 onsent 事件将数据从窗体区域附加到实际电子邮件来解决它。