Send asynchronous mail using asp.net
Sending e-mail is an important and common feature in ASP.Net (through the system.net.mail namespace). In this article, I will show how to send asynchronous mail, which is used, for example, to send bulk e-mail. ASP.Net includes the feature of asynchronous mail.
Following is an example of sending asynchronous mail:
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";
}
}
MSDN link : http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx
Video Tutorial : http://www.asp.net/learn/videos/video-420.aspx
Revision number 6, Tuesday, November 03, 2009 7:17:17 PM by mbanavige
You must Login to comment.
|
Sun, Nov 16, 2008 9:16 PM
by atarikg
|
Could you tell me why I need to use something or when I need to use this technic. thanks
|
|
Thu, Dec 11, 2008 2:19 AM
by ashrafur
|
http://msdn.microsoft.com/en-us/magazine/cc163463.aspx - Read that article to know benefits of asynchronous programming and then you will realize how much important sending asynchronous mail specially at the time of sending a bunch of mail at once.
|
|
Mon, Apr 26, 2010 1:12 AM
by venkatu2005
|
Is that code working with error free..
|
|
Tue, May 24, 2011 3:04 AM
by kirank28
|
http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx is not working
|
|
Wed, Feb 29, 2012 2:44 PM
by boris.momtchev
|
Almost...
Read this:
http://blog.jdconley.com/2009/01/fire-and-forget-email-webservices-and.html
|