UiPath Office365Message object to MailMessage object?

I’m working on a Office365 demo for automating attachments and I’m stuck on using the “Save Attachments” activity. The Office365 “Get Mail” activity produces a Office365Message object and “Save Attachments” wants a MailMessage object.

Sorta stuck on what to do about it. Do I need to convert the Office365Message to a MailMessage Object ? If so, how would I got about that ?

Or is there something else I’m missing here ?

TIA

I’m not a .NET nor daily developer of anything. So … I got it working without fully understanding why it worked but tried something based on a little between-the-lines reading of other posts. Hoping for some explanation so I understand it. Question in graphic repeated here : Is a Office365Message object an array of MailMessages ?

@soneill437 Did you find a solution to converting from convert Office365Message to System.Net.Mail.MailMessage?

Hi @soneill437,

Short answer:
No, but kind of. The Office365Message array is not an exact type match for MailMessage array (Office365Message <> MailMessage). Due to inheritance, Office365Message is a child class of MailMessage and can be type casted as a MailMessage, and then manipulated as a MailMessage. By type casting the Office365Message Object into a MailMessage Object, it effectively becomes a MailMessage Object in the eyes of the .NET Framework.

Explanation of your findings:
emailReadResult is an array of Office365Message messages.
Your For Each loop is type casting the email messages from Office365Message Objects to MailMessage Objects via the TypeArgument Misc value selected in the Properties pane.

You are essentially performing this action by selecting MailMessage in the For Each loop TypeArgument (instead of Office365Message):
CType(omessage, MailMessage)
image
image

CType documentation

More information:
The Office365Message class inherits the System.Net.Mail.MailMessage class, which means the Office365Message class inherits all of the same constructors, methods, and properties as MailMessage plus it has the constructors, methods, and properties that it owns as well. The biggest usage difference between the Office365Message class and the MailMessage class is that the Office365Message content is derived from the Microsoft.Graph.Message, allowing Office365Message Objects to have more robust features and functionality in relation to the Microsoft Graph Gateway.
C# Inheritance Tutorial
Wikipedia Inheritance

Thanks

I am trying to type cast the office365Message as you’ve mentioned but still unable to save the emails in .msg format. Could you please help?

Hi @Shah_Hussain,

Did you try to use the Save Email activity or the Save Outlook Mail Message activity? One of these activities should allow you to save the email in memory as an .msg file.

Thanks

Hi Kristopher,

I have tried both but not working. I have moved to Office365 activities because I wanted to remove dependency on outlook application and all working well with office365 so far until this use-case (Save emails in .msg format).
When I try Save outlook Mail Message, I get the below error.

And another save email activity also requires outlook application and maybe I will have to install a package to get it working.

Is there a way to convert office365 package to mailmessage or maybe VB code cause I have not been able to find it?

Hi @Shah_Hussain,

There is a marketplace component available that can help with saving Office365Message objects to .msg files.

.NET code is somewhat cumbersome because the MailMessage must be converted to an other type of object that has a save method (e.g. interop libraries)

Thanks

Thanks, Kristopher!
I saw this package earlier but I wanted something wherein I do not have install any third party package. Thanks though!