从eml文件中提取msg附件

时间:2018-06-07 01:02:19

标签: c# mapi outlook-redemption

我正在尝试从EML附件中提取MSG文件,我可以让脚本生成附件的名称,但我无法弄清楚如何将附件保存到PST而不是EML,我的代码如下所示

resample

任何帮助将不胜感激

2 个答案:

答案 0 :(得分:1)

您已结束,但需要使用.EmbeddedMsg property来获取MSG文件。下面的示例代码。

Dim fileItmName As String 'The fullname of the EML file including path
Dim RMsg, AMsg

'Outlook folder
Set fldrOutlook = RSession.GetDefaultFolder(olFolderInbox).Folders("[Subfolder]").Folders("[Subfolder]")  'etc.

'Bring EML message into Outlook (you can delete it after you pull the attachment)
Set RMsg = fldrOutlook.Items.Add
RMsg.Sent = True
RMsg.Import fileItmName, 1024
RMsg.Save

'find msg attachment
'https://msdn.microsoft.com/en-us/vba/outlook-vba/articles/attachment-object-outlook
For Each attch In RMsg.Attachments
    If Right(attch.FileName, 4) = ".msg" Then 'In case the EML message has more than one attachment.
        Set AMsg = attch.EmbeddedMsg 'This is the MSG message you are trying to get.

        'Process the message

    end if


Next attch

答案 1 :(得分:0)

由于您不想要外部消息,因此您需要首先获取内部消息。调用RDOSession.CreateMessageFromMsgFile创建临时MSG文件(稍后可以删除),使用RDOMail.Import导入外部消息,遍历附件并使用RDOAttachment.EmbeddedMsg(返回RDOMail对象)。然后,您可以使用RDOMail.CopyTo()复制该邮件,并传递新创建的(mail)对象或目标文件夹(RdoFolder)。