简体   繁体   English

如何在 Outlook VBA 中访问 EmbeddedItem 附件

[英]How to access EmbeddedItem attachment in Outlook VBA

I am using Outlook 2010 and the QuickSteps only allow to create a Task from an email with the email body copied to the task body or with the email as attachment.我使用的是 Outlook 2010 并且 QuickSteps 只允许从电子邮件创建任务,并将电子邮件正文复制到任务正文或将电子邮件作为附件。

I already have a small script which is called when a new task object is added to the task directory.我已经有一个小脚本,在将新任务对象添加到任务目录时调用该脚本。 If I have a an email attachment to the task I would like to copy its body to the task body.如果我有任务的电子邮件附件,我想将其正文复制到任务正文。

Public WithEvents OlItems As Outlook.Items

Sub Application_Startup()
    Set OlItems = Session.GetDefaultFolder(olFolderTasks).Items
End Sub

Sub OlItems_ItemAdd(ByVal Item As Object)
    Dim obApp As Application

    If Item.Class = olTask Then
        Item.Status = olTaskDeferred

        If Item.Attachments.Item(1).Type = olEmbeddeditem Then
            Dim attachment As attachment
            Set attachment = Item.Attachments.Item(1)
            Debug.Print (attachment.FileName)
            '???: Item.body = attachment.body
        End If

    Item.Save
    End If

    Set obApp = Nothing
End Sub

The attachment is of type olEmbeddedItem.附件的类型为 olEmbeddedItem。 I can't figure out how to open/read from it?我不知道如何打开/读取它?

Is this possible?这可能吗? My goal is to have both body and email attachment in the task item.我的目标是在任务项中同时包含正文和电子邮件附件。

Outlook Object Model will not let you directly access embedded message attachments - if you were using C++ or Delphi, you could use Extended MAPI to open the embedded message attachment using IAttach::OpenProperty(PR_ATTACH_DATA_OBJ, IID_IMessage) . Outlook 对象模型不会让您直接访问嵌入的邮件附件 - 如果您使用 C++ 或 Delphi,您可以使用扩展 MAPI 使用IAttach::OpenProperty(PR_ATTACH_DATA_OBJ, IID_IMessage)打开嵌入的邮件附件。

The only workaround is to save the attachment as an MSG file ( Attachment.SaveAsFile ) and open it using Application.Session.OpenSharedItem唯一的解决方法是将附件另存为 MSG 文件 ( Attachment.SaveAsFile ) 并使用Application.Session.OpenSharedItem打开它

Or you can use Redemption (which wraps Extended MAPI and can be used from any language) and do something like the following:或者您可以使用Redemption (它封装了扩展 MAPI 并且可以在任何语言中使用)并执行如下操作:

RDOSession session = new RDOSession();
RDOMail msg = (RDOMail)session.GetRDOObjectFromOutlookObject(YourOutlookMailItem);
foreach (RDOAttachment att in msg.Attachments)
{
    if (att.Type == rdoAttachmentType.olEmbeddedItem)
    {
        RDOMail embeddedMsg = att.EmbeddedMsg;
        ProcessEmbeddedMessage(embeddedMsg);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM