【问题标题】:How to Open Outlook file attachment directly not saving it? ( with C# VSTO)如何直接打开Outlook文件附件而不保存? (使用 C# VSTO)
【发布时间】:2020-07-22 08:02:21
【问题描述】:

我需要直接从邮件中打开邮件文件附件。假设我有 .txt 文件。我已经将它附加到我的邮件中。但是现在我需要打开它,更改一些单词并保存它(它是手动部分)。我怎样才能做到这一点?我的代码是:

private void button2_Click(object sender, EventArgs e)
        {
            Outlook.Inspector currInspector = null;
            Outlook.MailItem mail = null;
            Outlook.Attachments attachments = null;



            currInspector = Globals.ThisAddIn.Application.ActiveInspector();
            if (currInspector != null) { 
            mail = (Outlook.MailItem)currInspector.CurrentItem;
            attachments = mail.Attachments;
            attachments.Add(@"C:\install\CSharp\tulemus.txt", Outlook.OlAttachmentType.olByValue);
               

            }

【问题讨论】:

    标签: c# email outlook vsto attachment


    【解决方案1】:

    Outlook 对象模型不为此提供任何属性或方法。您可以尝试从 Outlook 维护的缓存文件夹中读取附件。请参阅Finding Outlook temporary folder for email attachments 了解更多信息。

    此外,您可以使用低级 API(扩展 MAPI)访问 PR_ATTACH_DATA_BIN 属性,在 Opening an attachment 文章中阅读有关算法的更多信息。

    【讨论】:

    • 请注意,OOM 不允许您使用 PropertyAccessor 对象访问大型 (>32 kB) MAPI 属性。
    • @DmitryStreblechenko 实际上我的帖子中没有提到 OOM。扩展的 MAPI 允许使用流等访问大型属性。
    【解决方案2】:

    除了 Eugene 建议的 - 使用 Attachment.PropertyAccessor 或 MAPI(C++ 或 Delphi)来访问 PR_ATTACH_DATA_BIN 属性(DASL 名称 "http://schemas.microsoft.com/mapi/proptag/0x37010102") - 您还可以使用 Redemption:它的 RDOAttach.AsText /AsArray/AsStream 属性允许动态修改附件内容

    【讨论】:

    • OOM 不允许您使用 PropertyAccessor 对象访问大型 (>32 kB) MAPI 属性。因此,正如我在帖子中所说,可能的替代方法是使用低级属性(扩展 MAPI)。 Opening an attachment 解释了如何做到这一点。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-28
    • 2022-01-17
    • 2018-03-23
    相关资源
    最近更新 更多