c# - 防止 MailItem.Reply 在 Outlook 2016 中打开检查器窗口
问题描述
当用户单击“回复”按钮时,我正在为 Outlook 构建一个插件以在 Outlook 电子邮件中添加自定义签名。一旦用户点击资源管理器中的回复按钮,一个新的检查器就会打开,我用代码(s#cks)关闭检查器。可能有一种方法可以完全禁用回复检查器的打开。
private Microsoft.Office.Tools.CustomTaskPane CustomTaskPane;
UserDetail usr = null;
Outlook.Explorer currentExplorer = null;
Outlook.MailItem mailItem;
private Inspector replyInspector;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
currentExplorer = this.Application.ActiveExplorer();
currentExplorer.SelectionChange +=
new Outlook.ExplorerEvents_10_SelectionChangeEventHandler(CurrentExplorer_Event);
}
private void CurrentExplorer_Event()
{
if (this.Application.ActiveExplorer().Selection.Count == 1
&& this.Application.ActiveExplorer().Selection[1] is Outlook.MailItem)
{
if (mailItem != null)
{
// when the reply button is clicked
((Outlook.ItemEvents_10_Event)mailItem).Reply -= new Outlook.ItemEvents_10_ReplyEventHandler(MailItem_Reply);
// When an item is selected
Outlook.Selection mySelection = this.Application.ActiveExplorer().Selection;
Outlook.MailItem mailitem = null;
foreach (Object obj in mySelection)
{
if (obj is Outlook.MailItem)
{
mailitem = (Outlook.MailItem)obj;
if (mailitem != null)
{
if (mailitem.Sent)
{
else
{
// Compose
}
}
}
}
}
mailItem = this.Application.ActiveExplorer().Selection[1];
((Outlook.ItemEvents_10_Event)mailItem).Reply += new
Outlook.ItemEvents_10_ReplyEventHandler(MailItem_Reply);
// Close Inspector
replyInspector.Close(OlInspectorClose.olDiscard);
}
else
{
}
}
void MailItem_Reply(Object response, ref bool cancel)
{
try
{
MailItem mitem = (Outlook.MailItem)response;
replyInspector = (mitem).GetInspector;
replyInspector.Activate();
(mitem).HTMLBody = tempSignature + ((Outlook.MailItem)response).HTMLBody;
}
catch (System.Exception e)
{
MessageBox.Show(e.ToString());
}
}
解决方案
首先,如果您要打开检查器,为什么还要关闭它?为什么不在检查器打开时插入签名?
其次,您不能连接两个 HTML 字符串并期望生成的字符串是有效的 HTML,这两个需要合并。或者,更好的是,使用 Word 对象模型(Word.Document
返回自Inspector.WordEditor
)在邮件正文的任何位置插入任何文本。
推荐阅读
- javascript - 如何在 PeerJs peer.call(id, stream, [options]) 函数中设置元数据?
- flutter - 如何在 Flutter 中手动计算布局
- sql-server - 在 SQL Server 中制作摘要报告
- python - 使用 python 或 node.js 将平面文件从 SFTP 上传到 S3
- google-sheets - 谷歌表格公式在创建新表格之前不起作用
- python-3.x - 如何合并单元格而不丢失 libreoffice-calc 中的数据?
- django - 为什么我的 websocket 在 Django Channels App 中不断断开连接?
- ios - 本机:未安装 InAppBrowser 或您正在浏览器上运行。回退到window.open。在 iOS 上
- c# - 如何使用 C#/.NET 使用多个“Where”表达式并将它们与 AND 和 OR 链接在一起?
- regex - 在 vb.net 中使用正则表达式