Get Outlook messages

Hi all

I’m having a bit of an issue with the “Get Outlook messages” activity. I want to get any emails in my “Test” folder and save the attachment to my Desktop. Eventually I want to put different types of attachments in different folders (i.e. .xsl files in a “Spreadsheet” folder, .pdf in “PDFs” etc), but I’m having trouble getting over the first hurdle.

I run it (so far just downloading an attachment to the desktop), and get the error “Received : Value cannot be null. Parameter name: path” in the output box. This error also pops up:

wfException

This is my workflow:

getProperties
(properties are shown on the right)
saveProperties
(again, properties for this is included in the screenshot)

I’ve had a look in past topics and saw that the account doesn’t have to be defined as it’s the only one used on this computer. I’ve also tried it with and without and I’m still getting the same error, and I literally have no idea how to fix it.

Any suggestions?

Thanks!

1 Like

Hi Short!

Is it possible that one of the emails in your list of emails has no attachments in it? Or that the Outlook folder you are pointing to either doesn’t exist or has no emails in it? (One of these would be one of my first guesses based on the the “Value cannot be null” error.)

One way you might be able to get around the potential problem of having zero (or multiple) attachments in a single email is by having two “For Each” loops, one inside the other. The first “For Each” loop will be exactly like the one you have already built, going through each of the emails in your Emails variable (which should be of type List< MailMessage >). The second “For Each” loop would then be for going through each attachment in that single email item. So the inner loop would look something like this:

image

(Note: For this to work with your robot the way you currently have it setup, you would put “item.Attachments” instead of “mail.Attachments”. The “mail” in my example is simply the item name I assigned to each of the emails in my outer loop rather than the default name of “item”.)

One other thing to double-check is that the TypeArgument in the properties of your “For Each” loop is correct. For your current loop the TypeArgument should be System.Net.Mail.MailMessage. If you were to create the inner “For Each” loop I suggested above, that TypeArgument would need to be System.Net.Mail.Attachments.

Let me know if any of that helps!

Cheers,
Riley

EDIT: I also just noticed that your “Account” argument in your “Get outlook mail messages” activity is blank. You might double-check to make sure you don’t need to fill this in in order to access your specific Outlook folder.

Hi Riley

Thanks for the response!

That was my thought orginally too but the emails in the folder do have attachments, I’ve even moved it to “Inbox” in case the sub-folder was the issue, changed it from “OnlyUnreadMessages” to all, etc, everything I can think of but nothing is working.

With the “Account” being blanked, I read through an old forum post (trying to find a solution to this instead of posting a new one) and saw someone said the account doesn’t have to be defined if it’s the only one used on this computer. I’ve added the account back in and it still doesn’t work.

The Emails variable and “For each” TypeArgument are correct as far as I’m aware

emailType

typeArgument

Any other suggestions? I can’t tell you how insane this is making me and it’s probably something really simple I’ve overlooked!

Question: have you checked how many Emails were retrieved? You can check that in a message box or write line with Emails.Count, I believe.

If there are no Emails, you could get a Null exception.

It might also be isolated to certain Emails if there are no Attachments on some. Just a thought.

Thanks.

Hey

I put a write line after the “Get outlook mail messages” activity and it comes up with the error before it gets the chance to write it. At least now I know the error is with that activity and not the “For each”, thanks!

Hey,

I did some testing to see if I could replicate this error by specifically messing up the input for my “Get outlook mail messages activity”. I tried putting different types of inaccurate data for “Account” and “MailFolder”, tested with both checked/unchecked “OnlyUnreadMessages”, etc. Unfortunately I could not replicate the error.

Based on this, I am wondering if one of the following is the case:

  1. Perhaps your Outlook isn’t installed as “expected” by UIPath so the activity is unable to find Outlook altogether.
  2. Perhaps this is a variables problem. (Just a guess since you did not include variables in your original screenshot.) Two possibilities for this: (A) You might double-check to see if you accidentally created a duplicate of your Emails variable in two overlapping scopes. I can see how this could potentially (?) cause the robot some sort of confusion here. (B) If you accidentally created “Emails” as a different variable type besides “List< Mailmessages >” that you were somehow able to put in as the output for your “Get outlook mail messages” activity without UIPath recognizing it as a Compile Error, I have no doubt this would throw some sort of weird error when you tried to run your process. Just to double-check, your Emails variable is setup like so, correct? →

One last thing to ask just as a triple-check: You’re sure the error is coming from one of the steps you posted and not from something in the process right before this, correct? (I.e. if you put a Write Line or Message Box right before your “Get outlook mail messages” activity, it will activate prior to the error?) I’m sure you’ve probably checked this, but just making doubly-sure since I can’t see the rest of your process.

Cheers,
Riley

Hey

Thanks so much for all of this. After reading, I thought maybe there had been a change to the firewall which blocked something between UiPath and Outlook so I ran another project where an email is sent out, and that worked fine. On the same project, I re-built this and it worked fine. I compared the two processes and everything was exactly the same, however I kept getting the same error on this process. I’ve now deleted the project file, started again and it’s working how it should.

I’m still none the wiser about why it wasn’t working but if I’d thought of your point 1 yesterday, it would’ve saved me a lot of time, so thank you for saving me!

Awesome! Sorry we weren’t able to figure out exactly what was happening, but glad you’ve got it figured out now, at least. haha :slight_smile:

Cheers,
Riley

hi guys,
There also an another way to get the outlook messages without using any activity
check the below sample
OutlookInvoke (1).xaml (6.1 KB)

Regards
Sanjay Shankhla

2 Likes

hi Sanjay :slight_smile:
I wanted to ask you whether you also have some invoke Code to get the mails that are not from Outlook including getting the attachments (and checking the extensions of the corresponding attachments)? thank you!

hi
Use the below Code to choose the Account name and send the mail using invoke code

OutlookInvoke (1) (2).xaml (6.5 KB)

Regards
Sanjay Shankhla

3 Likes

Thank you that ws really helpfull.
where can I learn more codes like that.
I already have experiance in the VBA codes.
but it says it only works inside email scope!

plus I get this error when I choose the mail type.
18.4.1+Branch.master.Sha.bc66386dd8e2160b6d35f31d5ce934a5aa4cf4bd

The workflow has validation errors. Review and resolve them first.

Compiler error(s) encountered processing expression “mail”.
Value of type ‘1-dimensional array of System.Net.Mail.MailMessage’ cannot be converted to ‘System.Collections.Generic.List(Of System.Net.Mail.MailMessage)’.

Hi Short,
Can I get a working example of the .xaml please.
cheers
Ben.