Creating an UiPath.MicrosoftOffice365.Models.Office365Message object from scratch

Hello everyone,

currently I want to test some processes of a bot I created, which was written in C#, and one of these processes has an argument with the type UiPath.MicrosoftOffice365.Models.Office365Message.

I would like to test this specific process independently, therefore I want to create a new object of said type.

The problem is I can’t.

There doesn’t seem to be a developer doc for these kind of things, so I don’t know if there is even a constructor, and all my attempts to create a new object failed.
I also tried to cast a System.Net.Mail.MailMessage object to …Office365Message, but that didn’t work. I guess because System.Net.Mail.MailMessage is a subtype of …Office365Message.
I tried to cast it with “(…Office365Message) new System.Net.Mail.MailMessage” and also with “as”, but neither did work.

So my question is the following:
How can I create a new object of type “UiPath.MicrosoftOffice365.Models.Office365Message” in a C# Project?

This question was already asked a couple of times over the years [topic1][topic2][topic3], but none of them were really answered, and they also targeted VB instead of C#.

I have also created a simple test project, if somebody likes to take a look and play around:
Office365MailMessageConvertTestProject.zip (2.9 KB)

Hi @niki.rmoutil ,

Could you let us know if you were receiving a Validation Error or a Runtime Error ?

Currently, From your project, I have repaired the dependencies to have the latest stable version :
image

Then I do not receive any error in the Assignment or Conversion.

Possible cause of error is missing parentheses in constructor.

@niki.rmoutil

I dont think you can directly create…instead why not use a get mail before it and pass the value as needed

cheers

Could you let us know if you were receiving a Validation Error or a Runtime Error ?

Both? Depends on what I tried.

If you start the test project you will get the following runtime error:

The blocks which I commented out are validation errors

Then I do not receive any error in the Assignment or Conversion.

Did you also run the bot? Because I am always getting a runtime error, independent of if the package is a stable one or a preview.
The screenshot above is with the same packages as you have in your screenshot

I tried it with all paranthesis variations, nothing seem to work.

That’s my last resort, and I will do that if there is no other solution.
But to why I don’t want that: I would like to have as few dependencies as possible, and the process I want to test doesn’t interact with outlook or the microsoft servers. It only needs the data which is stored in the mail object

@niki.rmoutil

No New dependency has to be loaded…as office365 mail objetc comes from same dependency as the get mail activity of office 365…Ideally we get mail object after interacting only…may be it is a different bot I guess

creating a office365 mail Object I dont think is directly possible with values.

Never the less if you are able to achieve some way would really appreciate sharing it across…

cheers

Sorry for the confusion, I didn’t mean a UiPath dependency, but instead an external dependency so to say.

The problem with the get mail activity is that I would need to have a valid outlook account specified and there must also be a test email in this account.
That I would like to avoid.

In my best case scenario I create a Office365Message object with the necessary data (which by the way works with System.Net.Mail.MailMessage) and then give it to the process and look if the process did everything correct.
No Outlook involved and I can save all the testdata in the bot itself, therefore no unnecessary dependecies

1 Like

I tested this as well, and your right, it doesn’t work. For some reason the constructors for Office365Message are not exposed :person_shrugging:

As a workaround, I was able to create an Office365Message by deserializing from a string.

  • Create a string representing the message:
{
    "Message": "... (actual content omitted)",
    "BodyAsHtml": "",
    "Account": ""
}

Note that the message needs to be in a certain format - you can serialize a real Office365Message for a sample.

  • Deserialize the string to an Office365Message:
message = Newtonsoft.Json.JsonConvert.DeserializeObject<Office365Message>(serializedMail)
1 Like

That is an excellent idea, thanks a lot!

My PC has currently some permission issues, so I can’t test it right now. But there is no reason why this should not work.

As soon as these issues are resolved I will upload a working example.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.