Dispose of attachments in Send Exchange Mail

email
activities

#1

Hi,

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


#2

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.


#3

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 ?


#4

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.


#5

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.

Regards


#6

I have already raised in a private forum.

Thanks.

Richard


#7

Adding @qateam just to be sure…


#8

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


OCR Loop with try catch
How to insert attachment in UI path SMTP activity
SMTP and delete file error
The process cannot access the file 'PATH' because it is being used by another process
#9

Hello,

It seems to work !
Thanks a lot vvaidya


Unable to launch process because of tmp file access denied
#10

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:


#11

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


#12

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


#13

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


#14

Thanks vvaidya for your help…


Getting Exception Type : InvalidCastException