首页 > 解决方案 > 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?

标签: c#outlookvstooutlook-addinmapi

解决方案


您可以改为在“Items.ItemAdd已发送邮件”文件夹中的事件中进行处理 - 届时将保存消息。


推荐阅读