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

Posted on 2007-10-12
Last Modified: 2008-01-09
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);

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?
Question by:dbdp
    LVL 4

    Expert Comment

    Add an event handler to the SendCompleted event.

    Author Comment

    how do I do that?
    LVL 4

    Accepted Solution

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now