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”: “1.0.0.0”,
“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

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

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

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)

@Rahul_kumar_s

Attachments is the collection of Attchment you got from mail.

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

Regards,
Mahesh

@Rahul_kumar_S
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)