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;
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
The ASP.NET Wiki was started by Scott Hanselman in February of 2008. The idea is that folks spend a lot of time trolling the blogs, googlinglive-searching for answers to common "How To" questions. There's piles of fantastic community-created and MSFT-created content out there, but if it's not found by a search engine and the right combination of keywords, it's often lost.
The ASP.NET Wiki articles moved to CodeProject in October 2013 and will live on, loved, protected and updated by the community.