Outlook 加载项无法读取附件路径

Outlook add-in failed to read attachment path

我试图在从 outlook 发送邮件之前获取附件路径。但是,当我尝试这样做时,结果 null。这是我的代码:

public partial class ThisAddIn
{
    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        Application.ItemSend += new Outlook.ApplicationEvents_11_ItemSendEventHandler(Application_ItemSend);
    }

    void Application_ItemSend(object Item, ref bool Cancel)
    {

        Outlook.MailItem mail = Item as Outlook.MailItem;

        var atts = mail.Attachments;

        foreach (Outlook.Attachment attachment in atts)
        {
            MessageBox.Show(attachment.PathName); // the PathName is null !
        }
    }

    private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
    {

    }
}

用户创建新邮件并添加已在硬盘上的附件。如何获取所选文件的路径信息?

PathName property of the Attachment class returns a string representing the full path to the linked attached file. The property is only valid for linked files. Check out the Type 属性 值。

附件是原文件的副本,即使删除原文件也可以访问。 IE。原始文件路径未与附件一起存储。

该信息未存储在 Outlook 中。在低级别(扩展 MAPI)上,附件甚至不必来自文件。假设一个文件是从另一封 Outlook 邮件中拖出的——根本没有物理文件。

为什么路径很重要?