1

I am trying to extract an MSG file from an EML attachment, I can get the script to produce the name of the attachment but I cannot figure out how I get the attachment to be saved to the PST rather than the EML, my code looks as follows

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();

Any assistance will be appreciated

Jakes
  • 11
  • 2
  • Do you mean an embedded message attachment from the EML file that you are importing? So you want to import the embedded message attachment only but not its parent message? – Dmitry Streblechenko Jun 07 '18 at 03:27
  • Hi yes that’s correct, I have EJF messages so they have the original message attached as an SJF file. I have since added a variable that gets populated by running mail. Attachments and I can see the MSG file name, just not sure now how I can pull that out and push it into the PST. – Jakes Jun 08 '18 at 15:44

2 Answers2

1

You are close, but need to use the .EmbeddedMsg property to get the MSG file. Example code below.

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
SCORP.io
  • 140
  • 1
  • 9
0

Since you don't want the outer message, you need to get to the inner message first. Call RDOSession.CreateMessageFromMsgFile to create a temporary MSG file (you can delete it later), import the outer message using RDOMail.Import, loop through the attachments and use RDOAttachment.EmbeddedMsg (return RDOMail object). You can then copy that message using RDOMail.CopyTo(), passing either your newly created (mail) object or the target folder (RdoFolder).

sgriffin
  • 337
  • 1
  • 9
Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78