cancel
Showing results for 
Search instead for 
Did you mean: 

Read text from msg file

MateuszWojcik
Level 5
Hello,

I work on msg file.

Does any one have action to read whole text directly from msg file?

I have found a solution to converet msg file to txt file and then read text from txt file. I look for shortcut.

Kind regards

------------------------------
Mateusz Wojcik
RPA Programist
Rockwell Automation
Europe/Warsaw
------------------------------
11 REPLIES 11

You can use the Get Sent Items action in MS Outlook VBO to read body and other email attributes.

Regards,
Pratyush

------------------------------
Pratyush Garikapati
ROM Architect
Blue Prism
Asia/Kolkata
------------------------------

Hello Pratyush,

My case is to read msg file not email.

Kind regards

------------------------------
Mateusz Wojcik
RPA Programist
Rockwell Automation
Europe/Warsaw
------------------------------

At this moment I don't see out product having that function.
Maybe download a free program to read that file and them BP takes from there what you need.

Have a good day.

------------------------------
Luis Lopez
Customer Support Engineer English and Spanish
Blue Prism Ltd
------------------------------

Hello Mateusz,

I misread your original query. You'll have to create a custom VBO to read a .msg file as BP doesn't have that available within its standard VBOs.
Try this and let me know if it works.

Input: File Name (text - full path and name)

Output: Items (collection)

Code:
Dim app = CreateObject("Outlook.Application")
Dim _nameSpace = app.GetNameSpace("MAPI")

'Dim item As Outlook.MailItem
Dim item as Object
item = app.CreateItemFromTemplate(File_Name)

Dim dataTable As New Data.DataTable
dataTable.Columns.Add("To", Type.GetType("System.String"))
dataTable.Columns.Add("CC", Type.GetType("System.String"))
dataTable.Columns.Add("Subject", Type.GetType("System.String"))
dataTable.Columns.Add("Body", Type.GetType("System.String"))
dataTable.Columns.Add("Attachments", Type.GetType("System.String"))
dataTable.Columns.Add("ReceivedOn", Type.GetType("System.DateTime"))
dataTable.Columns.Add("SentOn", Type.GetType("System.DateTime"))
dataTable.Columns.Add("SenderName", Type.GetType("System.String"))
dataTable.Columns.Add("SenderEmailAddress", Type.GetType("System.String"))

Dim row As Data.DataRow = dataTable.NewRow
row("To") = item.To
row("CC") = item.CC
row("Subject") = item.Subject
row("Body") = item.Body

Dim attachments As String = ""
For Each attachment As Object In item.Attachments
If attachment.Type = 1 Then
attachments = attachments & "|" & attachment.DisplayName
End If
Next

row("Attachments") = If (attachments.Length = 0, "", attachments.SubString(1))
row("SentOn") = item.SentOn
row("ReceivedOn") = item.ReceivedTime
row("SenderName") = item.SenderName
row("SenderEmailAddress") = If (item.SenderEmailType = "EX",item.Sender.GetExchangeUser.PrimarySmtpAddress,item.SenderEmailAddress)
dataTable.Rows.Add(row)

Items = dataTable


------------------------------
Pratyush Garikapati
ROM Architect
Blue Prism
Asia/Kolkata
------------------------------

Thank you Pratyush Garikapati

------------------------------
Mateusz Wojcik
RPA Programist
Rockwell Automation
Europe/Warsaw
------------------------------

Hi Pratyush,

I tried the above code and getting 1 error as follows
Stage: Code
Type: Error
Action: Validate
Description: Compiler error at line 1: 'CreateObject' is not declared. It may be inaccessible due to its protection level.
Repairable: No

------------------------------
Pramod Prasad
Consultant
EY
Asia/Kolkata
------------------------------

Hi Pratyush,

I am getting below error,
18655.png

------------------------------
Pramod Prasad
Consultant
EY
Asia/Kolkata
------------------------------

Hi Pramod,

Are you able to compile the code stage successfully and save the object?

Are you able to open the .msg file manually or do you get an error?

Regards,
Pratyush

------------------------------
Pratyush Garikapati
ROM Architect
Blue Prism
India
------------------------------

Yes , the code stage has zero errors, and i am able to save the object,
Yes i am able to open the file manually , also tried in other machine i am getting same error

------------------------------
Pramod Prasad
Consultant
EY
Asia/Kolkata
------------------------------