Save Attachments: Value cannot be null. (Parameter 'key')/ System.ArgumentNullException

Hello ,
I am trying to download all attachments from an email using IMAP (NOT Gmail and not Outlook)
I get an error : Save Attachments/Message : Value cannot be null/ System.ArgumentNullException

The strange thing is that it does download some of the attachments from some of the emails but it doesn´t finish the process I get this error.
Not sure if this error is received when an email doesn´t have an attachment . If yes what should I do so that the process omits these exceptions ?
This is the process and the error


Can’t you add an “If” condition to check if the mail has attachments, for each currentItem, before you use Save Attachments?

You can add this as the condition to an If activity:

currentItem.Attachments.Any

what would be the else activity in this case?

That would depend on what you want to do with emails with no attachments? You could leave it empty, if there’s nothing to do in such cases.

with the IF action I get the same error


Can you try upgrading the Mail activities package?

I did updated it, restarted StudioX and still got the same outcome, same error

Can you run it in debug mode, to see which email causes the exception to be thrown, and then check if there’s anything special in that email?

Are you sure that “Attachments” is initialized to an empty list when there are no attachments, rather than being just plain null? Can you try currentItem.Attachments IsNot Nothing?

You mean use it like this currentItem.Attachments.IsNot ?

The process I run involves a subfolder “Inbox/Factura”.
The strange thing is that if I run it to the main folder “Inbox” and not to the subfolder I don´t get this error . It doesn´t make any sense

Agreed with this approach, and in particular you might want to check whether the attachments have some weird characters in the file name (you never know).

I will check it , thanks

1 Like

Hello,

I have the same problem. When I looked into the mail message I saw that Studio recognize 2 attachments even if the email has only one. The first one is an empty attachment (Null name and also content)
The error is Save Attachments: Value cannot be null. (Parameter 'path2')

I already try to put some conditions to limit null attachments but without success.

Thx!

Hi @Cris_Webs

If there is no attachments in the mail it will throw that error.
To handle this error first check the mail has attachments.
In if condition write like this
Mailmessagevariabe.Attachements.Any

In then block give the save attachments activity.

Hope it helps!!

1 Like

The email has only one PDF document attached, but Studio find 2 attachments: 1 null attachment and the PDF file.
I already did the Attachment condition but I have the same error.
Also I tried to loop through attachments and save only the PDF file with the same result. Unfortunately I’m new user and I cannot attach screenshots.