Dispose of attachments in Send Exchange Mail


We send emails with attachments with the “Send exchange mail Message”. No issue with this.

Nevertheless, when we try to delete the file which has been sent, we get the message that a process is always using this file. After tests, we found that it is the send activity that don’t dispose the attachments.
Do you know this issue ? Do you have a solution ?

Thanks and regards

1 Like

You need to use Invoke Method to call the .Dispose method. If you cannot do this on the MailMessage itself (i.e. you need to keep using the MailMessage) then call it on the attachments object. You can google the Dispose method for more information on how to use it.

1 Like

I’ve also found this solution but with the “Send Exchange Mail Message” how can we get the object “MailMessage” sent or the object “attachments” in order to call the dispose method on them ?

Hi Nicolas, I understand your problem.

An alternative way of using the Message activities is to use the Invoke Methods to create the mail message in the first place. Therefore rather than just passing To, From, Subject, Attachment Path through to the activity you can pass through a MailMessage object and also an object of type attachments.

If I get a chance I’ll try to create an example for you. This method will then give you something to dispose once you are done using them and as they are separate you could dispose either the mail message, the attachments or both. We had this problem with files before which were being held in memory and could not be opened.

Hi Richard,
Many thanks for helping us.
We will have no other choice than to use this method.

Is-there somebody from UiPath ?
I think it is a real bug of the “send email” activity that should be resolved. Attachments have to be disposed after sending the email.


I have already raised in a private forum.



Adding @qateam just to be sure…

Invoking the below after your process might resolve the issue.Apologies if it doesn’t help



It seems to work !
Thanks a lot vvaidya

1 Like

Great! Thanks a lot!
I had the same issue with moving a file after used it as attachment.

Btw full MethodName is WaitForPendingFinalizer :slight_smile:


We maybe need “s” at the end of MethodName :slight_smile:

I am also facing similar situation. Even after using Invoke Method, I am getting the same error.
Can you please help me out here?

Not sure if this works, but try below invoke method.


Thanks vvaidya for your help…