c# - Outlook shows save confirmation dialog (message lose digital signature in case of saving) in Application.ItemSend event handler
问题描述
I'm developing Outlook VSTO add-in that checks Outlook.MailItem attachments. As far as I need to get access to internals of OLE and .msg file (embedded)attachments, I use glue with C++ Extended MAPI.
I received digitally signed message and when I'm trying to reply the save confirmation dialog is showing (with caption - "...If the changes are saved, the message will lose its digital signature.").
This behavior repeats only when I'm trying to make reply for digitally signed message. In the code below add-in call Save() for Outlook.MailItem (saves it into Drafts folder by default
and after that MailItem obtains EntryID), set Cancel=true and make some long work with attachments in another thread and if the work result is ok, add-in call MailItem.Send() programmatically.
Obviously this dialog shows when mailItem.Save() was called. But without mailItem.Save() call, I can't to obtain attachment type (PR_ATTACH_METHOD through GetProps or HrGetOneProp return NO_ATTACHMENT) in C++ part.
private void ApplicationItemSendHandler(object Item, ref bool Cancel)
{
Outlook.MailItem mailItem = null;
bool errorCaused = false;
try
{
mailItem = Item as Outlook.MailItem;
if (mailItem == null)
return;
if (mailItem.Attachments.Count == 0)
{
Marshal.ReleaseComObject(mailItem);
return;
}
if (String.IsNullOrEmpty(mailItem.EntryID))
mailItem.Save();
Cancel = true;
//make some long work with attachments.
}
catch (Exception e)
{
errorCaused = true;
Logger.Debug($"Error occured during call {MethodBase.GetCurrentMethod().Name}: {e.Message}");
}
finally
{
if (errorCaused && mailItem != null) Marshal.ReleaseComObject(mailItem);
}
}
My question - how to suppress or get around this dialog?
解决方案
您可以改为在“Items.ItemAdd
已发送邮件”文件夹中的事件中进行处理 - 届时将保存消息。
推荐阅读
- c# - 仅给出 1 个参数时,方法“ReadLine”参数没有重载
- google-apps-script - 如果范围在范围列表中
- python - Matlab/OpenModelica 生成的 FMU 是否支持 fmi2GetFMUState/fmi2SetFMUState?
- python - 得到 gai & socket 错误,我不确定这些是什么意思
- reactjs - 更新功能组件道具不会改变样式
- r - 在R中的DT Datatable顶部放置分页?
- powerbi - 如何基于 EnabledDate、EnabledDate + 1、EnabledDate + 2、EnabledDate + 7 和 power bi 上的日期过滤选项创建汇总表?
- java - 如何使用 Immutables 和 Egg 模式设置基类字段
- docker - docker 使用 nvidia 运行时构建
- html - Bootstrap 4 上的 Display 属性问题