Extract email subject body attachment from .msg UiPath
Many of times we work with outlook while automating a business process.
We need to extract the email subject, body, and attachment from the outlook mail.
If you have already done some automation using outlook then you probably know how we can achieve this from the new email in the inbox.
If you want to extract all the above-mentioned details from a new email in the inbox that can be achieved by using UiPath Outlook Activities.
But why the scenario that we are discussing in this article is different than the normal extraction of all these details from the email.
Let’s consider a scenario where we have a .msg file inside an email as an attachment.
So, we can save that .msg file attachment by using the UiPath outlook activities.
Now to extract the data from that .msg file is not done directly by UiPath Activities.
So in this post, we will see how we can extract the email subject, body, and attachment from the .msg file.
We are not using any outlook activities from UiPath to get this done but using vb script.
Step1: The input will be the .msg file as a outlook item.
Now we had the input file from where we have to extract the email subject, body, and attachment by using the vb script.
Step2: Drag and Drop Invoke Vb Script Activity from activities panel to the designer panel as shown below:
Then we need to pass the .msg file path as input argument as shown below:
Step3: Now let’s see the VBScript that is used for this task. The code is shown below:
Dim OlApp Dim Eml, Arg, File, mailExtractData Set Arg = Wscript.Arguments File = Arg(0) Set OlApp = CreateObject("Outlook Application") Set Eml = OlApp.CreateItemFromTemplate(File) Download(Eml) Sub Download(objEml) For Each Attch In objEml.Attachments mailExtractData= objEml.Subject & objEml.SenderEmailAddress & objEml.Body Attch.SaveAsFile "saving Folder Path" & Attch.FileName Next End Sub
- mailExtractData- This is the output of the script which will provide us with the email body, subject, and sender address.
Take a clear look at below line:
Attch.SaveAsFile "saving Folder Path" & Attch.FileName
- saving folder path – Provide the folder path where you want to save the attachments of the .msg file which is used as input.
This is how we can extract all the details from the .msg file.