Open Gaz83 opened 3 years ago
It looks like the issue is that AttachFromFilename opens a read stream which is never closed. I experienced the same issue with MailGun (which would make sense since the issue is in Core). My workaround is to call:
email.Data.Attachments.ForEach(async f => await f.Data.DisposeAsync());
after SendAsync to close attachment streams so I can then do what I want with the files. Not optimal but I don't know what to suggest as a better option since I'm not sure how those streams are used throughout the library. My solution may even cause issues somewhere else but it seems to be working for me for now.
I have a program listening to messages from a Message Broker (Rabbit MQ) and when a message comes in it sends an email. In the message I have a property with attachment path, which is an ftp site. I check if this is valid and download the attachment. Once downloaded I attach to the email and send.
What I am noticing is that if I send the email, move on to the next message and try to repeat the above with the SAME attachment, I get the following error System.IO.IOException: The process cannot access the file 'C:\Temp\Somepic.jpg' because it is being used by another process.
This happens at the point when I try to delete the attachment file.
I am using the MailKit as the sender.
A bit of code to help