Problem with Mail.Messages and Casting

Hi All

I am struggling to view emails that I have retrieved

I can scan a folder and check that a mail is present but I cant seem to open it. I think it has something to do with casting


I have tried to adjust to Web.Mail and that allows me to use .Body, .Subject etc but I cant seem to cast it correctly prior to this step

Trace below - Any suggestions

I had a look on forum but nothing to highlight step by step around what should be done

Email_Process has thrown an exception

Source: For each

Message: Unable to cast object of type ‚ÄėSystem.Net.Mail.MailMessage‚Äô to type ‚ÄėSystem.Web.Mail.MailMessage‚Äô.

Exception Type: InvalidCastException

System.InvalidCastException: Unable to cast object of type ‚ÄėSystem.Net.Mail.MailMessage‚Äô to type ‚ÄėSystem.Web.Mail.MailMessage‚Äô.
at UiPath.Core.Activities.ForEach1.InternalExecute(NativeActivityContext context, IEnumerator valueEnumerator) at UiPath.Core.Activities.ForEach1.Execute(NativeActivityContext context)
at System.Activities.NativeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

Hi @RogerFenergo,

If you are reading the mail from uipath activity it will return the datatype. You can’t convert net to web.

Arivu :slight_smile:

Thanks - how do I read the content though

Hi @RogerFenergo,

Using this data type its self you can use, refer the previous post and try it.

Arivu :slight_smile:

Here is some more detail on the error

Hi @RogerFenergo,

change the Properties->TypeArgumaent to ‚ÄúSystem.Net.Mail.MailMessage‚ÄĚ

Arivu :slight_smile:

Perfect - Thanks Arivu

unable to find mail.subject

Hi @rssawant0076

In the properties pane, it got set to System.Net.Mail.MailAddress rather than System.Net.Mail.MailMessage.

Hopefully this helps!

hi nlee1131
thnks for the help

1 Like