.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

How to Send Mail Asynchronously in asp.net

Posted By: Faizal     Posted Date: August 06, 2008    Points:2   Category :ASP.Net
How to send mail Asynchronously in asp.net.Please help me.

Faizal

Responses
Author: Pankaj Mishra             
Posted Date: August 06, 2008     Points: 5   

Hi Faizal,
If you are using .Net framework 2.0 onwards then you can use System.Net.Mail class and use SmtpClient class''s object SendSync() method to send mail

eg

MailMessage message = new MailMessage();

message.From = new MailAddress("from@fromAddress.com");
message.To.Add("sender@sender.com");
message.Subject = "Subject";
message.Body = "Message Body";
object userState = message;

SmtpClient client = new SmtpClient();
client.Host = "mail.sender.com";//your SMTP address

client.Credentials = new NetworkCredential("sender@sender", "yourPassword");
client.SendCompleted += new SendCompletedEventHandler(SmtpClient_OnCompleted);

try
{
client.SendAsync(message, userState);
}
catch (Exception ex)
{
throw ex;
}


public static void SmtpClient_OnCompleted(object sender, AsyncCompletedEventArgs e)
{
MailMessage mail = (MailMessage)e.UserState;

//write out the subject
string subject = mail.Subject;

if (e.Cancelled)
{
//Handle it
}
if (e.Error != null)
{
//handle it
}
else
{

}
mail.Dispose();
}


Hope this will help you

Cheers
Pankaj

Author: Rahul             
Posted Date: October 26, 2008     Points: 5   

Hi,
You can use system.Net.MailMessage class to send mail in asp.net

Author: Rahul             
Posted Date: October 26, 2008     Points: 5   

You can also use System.Web.Mail.MailMessage class to send mail



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend