Save Attachment - Length cannot be less than zero

Hello,
I use Save Attachment to download PDF file from email, however for one email case I got below error:
image

The activity works perfectly fine on any other emails, but just this one got the issue. Actually I donot see any difference on that email.

Did anyone experience same issue before? and why error is about parameter “length”, I can not find any details about “length” for Save Attachment.

Hi @Louis_liu !
Welcome to UiPath community :smile:
When you run it on debug mode, once the error is fetched, on the top left of your studio (in local panels) would you mind:

  • copy/paste here the remote exception
  • copy/paste the screenshot of the local panels as you can see in the following screenshot (what i would like to see is the value of this famous “name” that is found empty according to the displayed error)

Hello Hiba_B,
Thank you.
Here are screenshot might help:
image
image


image

I think Length Zero error is not for address path it’s for attachment. check if email does have attachment. if this is the issue then check attachment length before saving attachment.

Alright, and when you hover your mouse on the attach variable, on the right there should be a pen that is displayed, if you click on it what are the data that are in attach variable ? Is there a missing element ? (it would be great if you could screenshot it)

Thanks Hiba_B, here is screenshot. I found this attachment the parameter Position is 0, but in other emails the Position is always equal to Length, does it cause the issue? if so, is that possible to change the Position value?

Just tried to change position value to 11349, does not work, still got same error.

Hello Aditya,
Thanks for the help.
the email does have attachment and can be saved manually without any issue. The length of attachment is 113499, not 0. Is there any other parameter I can check?

@Louis_liu I’ve just run successfully a workflow with the following activities:

  1. Get Outlook Mail Messages → return one email having a 24 MB *.pdf attachment
  2. Save Attachments → it successfully saved the attached *.pdf file (even if Position = 0)
    image

For the time being I have no idea what can be the root cause of your issue.
Can you please try to attach that file to another test email and check whether it can be saved?

Hi @Hiba_B
I am having similar issue to this. When I look at the attachment variable (and click in the pen like you suggest), here is the local value it gives me below:

Attachment { ContentDisposition=[attachment], ContentId=“d13379cc-625a-4b2f-a69a-14154a6a1123”, ContentStream=MemoryStream { CanRead=true, CanRead=true, CanSeek=true, CanSeek=true, CanTimeout=false, CanWrite=true, CanWrite=true, Capacity=201407, Length=201407, Length=201407, Position=0, Position=0, ReadTimeout=!, WriteTimeout=! }, ContentType=[application/octet-stream; name=+1855228-0427-144027-134.pdf], Name=“+1855228-0427-144027-134.pdf”, NameEncoding=null, TransferEncoding=Base64 }

Hi @DylanT !
Thank you for sharing with us the whole error message.
As @ovidiuponoran suggests, may you try to send yourself a mail with the specific attachment called “+1855228-0427-144027-134.pdf” and use save attachment with the robot to see if the error concerns only the attachment or if it’s a specific bug with save attachment activity ?

1 Like

I had a similar issue and found a solution by implementing my own workflow for saving system.net.mail.mailmessage attachments. The solution is based on the answer found on this page.

CustomSaveAttachments.zip (3.0 KB)

2 Likes

@aaskov - I had to make little adjustments to make it work, because in the for each loop initially it was given as Mail(0).attachments which I guess will fetch the attachment only from the first item, so I was getting the empty result.

Plus added this , so that anyone can run…

Path.Combine(Environment.ExpandEnvironmentVariables("%USERPROFILE%\Downloads"), attachment.Name)

I’ve got the same issue. It worked just fine for 2 months. All of a sudden it doesn’t work anymore. It also works for 99% of the attachments, but some give the error message. Anyone got a solution?

Example: it throws an error for the pdf “dee01382495.pdf”

Same here…
A week ago the save attchments activity was just working fine with every letter, but now it is not working with a specific one, but the robot had worked on it before.

Please UiPath masters, help us! :smiley:

@m.slagter when the activity started to fail: did this happen with the same version of the mail activities package that had worked before?

Thanks for your reply.
I’ve checked with a backup. it’s indeed the package that has been updated… Any solutions?

@m.slagter can you please confirm the activity from Mail package 1.9.5 (or an earlier version!? - please let me know which version exactly) correctly saves the attachment of that particular email?

I can confirm it works for Mail package 1.9.5. and it doesn’t work for the newer version 1.10.4. I’ve just tested it.

1 Like

Faced the same issue. Had to uninstall the mail activities package and install the lower version