Outlook 插件 BeforeAttachmentAddEventHandler 中缺少附件类型

Missing attachment type in Outlook Addin BeforeAttachmentAddEventHandler

我有一个处理附件的 Outlook 加载项。我已经安装了一个处理程序来在添加附件之前捕获附件,以便我有机会处理它们。

以下代码用于工作但已停止,因为已拖入电子邮件的附件类型表单文件为 0。

void handleBeforeAttachmentAdd(Outlook.Attachment attachment, ref bool cancel)
        {


            try { 

                Outlook.OlAttachmentType type = attachment.Type;

                TDAddIn.log(String.Format("handleBeforeAttachmentAdd type : {0}",   type));
                if ((attachment.Type == Outlook.OlAttachmentType.olByValue)  && TDAddIn.canAddAttachment(true))
                {
                    // Do something
                }
            }

            catch (System.Exception exception)
            {
               // handl exception
            }

            return;

        }

有人知道这里发生了什么吗?我该如何处理?

巴里

正如德米特里所发现的,这似乎是一个 Outlook 错误。

要解决此 Outlook 错误,您可以添加一个 attachmentAdd() 处理程序并执行与在 handleBeforeAttachmentAdd() 中执行的操作相同的操作,但不是将 'cancel' 参数设置为 true,而是调用 attachment.Delete() 删除原来的附件。

void handleAttachmentAdd(Outlook.Attachment attachment)
{
            string tempFile = System.IO.Path.GetTempFileName();;
            try
            {

                if (attachment.Type == Outlook.OlAttachmentType.olByValue))
                {                       
                     attachment.SaveAsFile(tempFile);

                    if (MyAddIn.attachFile(tempFile, attachment.DisplayName))
                    {
                        attachment.Delete(); // Delete the original attachment
                    }                        
                }
            }

            catch (System.Exception exception)
            {
                // handle exception
            } 
            System.IO.File.Delete(tempFile);
}