[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1122
  • Last Modified:

Know when mail is sent (using smtpclient in c#)

I am using SMTPClient to send e-mail with a textfile as an attachment

My Code is
      System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(sSmtp);
      smtp.SendAsync(mail,null);

This works fine however I need to know when the mail is sent to be able to move the text file attachment with out getting the error that the file is being used by another process.

How can I do this?
0
dbdp
Asked:
dbdp
  • 2
1 Solution
 
Die-TechCommented:
Add an event handler to the SendCompleted event.
0
 
dbdpAuthor Commented:
how do I do that?
0
 
Die-TechCommented:
Just like adding an event handler for any other object:
smtp.SendCompleted += new SendCompletedEventHandler(EmailSendCompleted);

That'll create method like this where you can do whatever you want:
private void EmailSendCompleted(object sender, AsyncCompletedEventArgs e)
{
   // delete my attachments or whatever
}
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now