Cannot get outlook attachment name

Hi i am trying to get attachment name from the outlook mail. but for some reason i couldnt get it.

here is the error

“message”: “Write line: Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index”,
“level”: “Error”,
“logType”: “Default”,
“timeStamp”: “16:14:08”,
“processVersion”: “”,
“jobId”: “80405317-41db-40d5-a367-4c3f89f51f6e”,
“robotName”: “UK\ZP137UN”,
“machineId”: 0,
“fileName”: “ReadMerchantEmails”

Attached the workflow
I am sure the email has attachment.GetMerchantRequestEmail.xaml (1.9 KB)

Hi @Rahul_kumar_S
if you want the name of the attachment the use below expression


in the above expression item represent the single mail.
and your workflow is blank .

1 Like

It throws

message": “Write line: Object reference not set to an instance of an object.”,

With this addition CType(item.Attachments.FirstOrDefault,system.Net.Mail.Attachment).Name.

Attached the workflow nowReadMerchantEmails.xaml (14.0 KB)


Attachments is the collection of Attchment you got from mail.

strAttachmentName= (From p In Attachements
                                    Select Convert.ToString(p.Name)).ToList(0).ToString


it is working fine , you will get the error if your mail doesn’t have the attachment, so before that you can do a check item.attachments.any

Hi Rishi, thanks for your reply! i did a boolean check for item.attachments.any it is throwing false though there is an attachment in email everytime

Am not sure if you guys have encountered the same issue on any scenario.

I have attached my get outlook mail properties screenshot.

Outlook version : 2013
Uipath version : Studio 2018.3.2 - 10/30/2018
Enterprise Edition
EXE Installer
Microsoft Windows 10 Enterprise 64-bit
.NET Framework Version 4.7

Uipath mail activity package version : 1.2.6863.29868

Please let me know your thoughts.

Email screenshot :

Do you guys is this because the security constraints of the outlook ?

Hi @Rahul_kumar_S
I think you are trying to use the company mailbox , there are lots of security check on the company mailbox so you won’t get the expected result. I will suggest you to try to use the same code on your personal mailbox or check with your company security team anyhow they won’t change their security policy.

1 Like

Agree @Rishi1 i will check with my security team

Try this.
It’s filtering on Subject, From and Attachmentname.
Outlook, Get_Attachment_from_Email.xaml (8.8 KB)

@ElectricBoogie @MAHESH1 @Rishi1 @Rahul_kumar_S @ppr @prasath17 @prasath_S @Yoichi @I.S @aksh1yadav

how to retrieve the name of the attachment of email , attachment can be .msg .pdf .xls .xlsx format
retrieve the list of string as list of all the attachments of email ?

@Sakshi_Jain - please open a new forum query instead of adding your query in old posts.

Please do not post samw query in multiple old posts …

@prasath17 is kind of right. It’s usually better to make a new query for it. However, the answer is alreay given in the file I shared above. Good luck @Sakshi_Jain!

This was the solution for me, changing Attachment to system.Net.Mail.Attachment