从eml文件中提取msg附件

问题描述 投票:1回答:2

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

session = new RDOSession(); 
session.LogonPstStore(C:\\temp\\outputfile.pst);                    
var mail = RdoFolder.Items.Add("IPM.Mail");
mail.Sent = true;
mail.Import(C:\\temp\\randomfile.eml, 1024);
mail.Save();

任何帮助将不胜感激

c# mapi outlook-redemption
2个回答
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

0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.