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

System.Net.Mail.MailMessage
System.Web.Mail.MailMessage

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 System.net.mail.mailmessage datatype. You can’t convert net to web.
mail_For

Regards,
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.

Regards,
Arivu :slight_smile:

Here is some more detail on the error

Hi @RogerFenergo,

change the Properties->TypeArgumaent to “System.Net.Mail.MailMessage”

Regards,
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