Business and Technology Consulting Organization in Mumbai

Electronic Transformation Globally Technology Solution IT Consultancy Service Provider

Send mail async in Asp.net 2.0

Masterpage in Asp.Net 2.0Asp.Net 2.0Session in Asp.Net 2.0
Generic in .Net 2.0Caching in .Net 2.0Async Mailing
Ado.net 2.0Asp.net data controlsAsp.net 3.5 new features


Now you can send email asynchronously with ASP.NET 2.0, here i have given step by step implementation

In page directive set the async=true.

 

<%@ Page Language="C#" MasterPageFile="~/MasterPages/CaseBasics.Master" AutoEventWireup="true"

    Codebehind="Pagename.aspx.cs" Inherits="Core.folder1.Pagename" Async="true" %>

 

 

Do the following in mail sending class.

 

using System.Net.Mail;

using System.ComponentModel;

 

public bool SendEmail()

        {

                    MailMessage mailMessage = new MailMessage();

                    this.mailMessage.From = new MailAddress(this.senderEmailAddress, this.senderName);

                                    

                 

                    this.mailMessage.IsBodyHtml = true;

                    this.smtpClient.EnableSsl = false;

                    this.smtpClient.Host = server.SMTP.Server ;

 

 

object userState = this.mailMessage;

                     this.smtpClient.SendCompleted +=new SendCompletedEventHandler(smtpClient_SendCompleted);

                     this.smtpClient.SendAsync(this.mailMessage, userState);

 

}

 

 

 

public static void smtpClient_SendCompleted(object sender, AsyncCompletedEventArgs e)

        {

            MailMessage mail = (MailMessage)e.UserState;

            string subject = mail.Subject;

 

            if (e.Cancelled)

            {

                //send cancelled

            }

 

            if (e.Error != null)

            {

                //errro occured

            }

            else

            {

                // mail sent successfully

            }

 

      }

Leave your comment.

Reduce your Dialy IT Cost, Consult with us
Stay healthy in recession

Advertisement
Sponsored by

HR Recruitment & Process Management System
Jewellery production process management software
Share
©2009 ETG Consultancy, All Rights Reserved Privacy Policy | Terms & Conditions
Asp.net, Ado.net, .Net Remoting, .Net Webservice, SQL, XML, XSLT, WCF, WPF, WWF NHibernate, Ajax, Jquery, DHTML