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 ?
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 ?
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)
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
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.
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.