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:

extract email body attachment

Then we need to pass the .msg file path as input argument as shown below:

extract email body attachment

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

Here:

  • 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

Here:

  • 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.

Happy Learning!

Like this post then let your friends know about this-:

4 thoughts on “Extract email subject body attachment from .msg UiPath

    • Author gravatar

      HI Aditya,
      I have tried the method but its throw me an error of end of expression expected.

    • Author gravatar

      Hi,

      Can you extract an attachment as well?

      Kathryn

    • Author gravatar

      Hi Aditya,

      I am Prasanna. I need your help in one task.

      The Scenario is after creating the user profile in application we need to send an email to the user that whether he got the access with Yes/No checkboxes. If user clicked on Yes option we need to track that response and we need to proceed further.
      If the user clicked on No bot needs send the reminder email to the user after 24 hrs. Still the user not responded bot need to send reminder emails 3 times in every 24 hrs.

      so here we are unable to find the logic. and we thought that we need to prepare the excel sheet with the details and user response column to track the user response. After that we are not getting the idea to move further and we are unable to find the logic for this.

      So can you please help me for this if you have time.

Leave a Reply

Your email address will not be published. Required fields are marked *