.Net Framework, Asp.net, Ado.net, .Net Remoting, .Net Webservice, SQL, XML, XSLT, WCF, WPF, WWF NHibernate, Ajax, Jquery, DHTML

Ado.netAsp.Net 2.0SQLC-SharpXMLFrameworkIISXMLWebServiceArchitecture
UMLProject ManagementSDLCMethodologiesDesign PatterenOOPWCF.Net RemotingWWF
MVPMVCSilver LightN-HibernateAjaxJ-QuerySEO-MarketingSite MapPhp

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.
Name
Email
Comments
Tell Us2158+5 =

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

Advertisement
Sponsored by

Privacy Policy ©2009 ETG Consultancy, All Rights Reserved Terms & Conditions
Asp.net, Ado.net, .Net Remoting, .Net Webservice, SQL, XML, XSLT, WCF, WPF, WWF NHibernate, Ajax, Jquery, DHTML