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 ?


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)

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