Home / ASP.NET Wiki / .NET Framework Essentials / Sending Asynchronous Mail

Sending Asynchronous Mail

 Rate It (2)

public void SendAsyncMail()
{
    MailMessage mail = new MailMessage();

    mail.From = new MailAddress("Enter from mail address");
    mail.To.Add(new MailAddress("Enter to address #1"));
    mail.To.Add(new MailAddress("Enter to address #2"));
    mail.Subject = "Enter mail subject";
    mail.Body = "Enter mail body";

    SmtpClient smtpClient = new SmtpClient();
    Object state = mail;

    //event handler for asynchronous call
    smtpClient.SendCompleted += new SendCompletedEventHandler(smtpClient_SendCompleted);
    try
    {
        smtpClient.SendAsync(mail, state);
    }
    catch (Exception ex)
    {

    }
}
    
void smtpClient_SendCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{

    MailMessage mail = e.UserState as MailMessage;

    if (!e.Cancelled && e.Error!=null)
    {
        message.Text = "Mail sent successfully";
    }
}

 

 

Nimish Garg
Software Programmer
Indiamart Intermesh Limited, Noida
http://nimishgarg.blogspot.com

Revision number 1, Thursday, March 18, 2010 7:33:43 AM by nimish_soft
This is not the most up to date version of this article. The most recent version can be found here.

Comments

it is better explain Asynchronous mail

how to use password recovery control use password recovery mail pls provide a code

Shortcuts

Table of Contents

Top Wiki Contributors

(last 30 days)

  1. abiruban (1)