When Our smtp Serve does not respond to immediately at that time it takes time to send email. So it happens that our application does not respond to user and user shut down our application. In this case its wise that we should send email Asynchronously and when email send successfully we just give notification it send successfully or not sent what so ever. This all things are available in the .net framework 2.0.
//Send email
SmtpClient sc = new SmtpClient(“smtp.abc.com”);
sc.Send(mm);
//Wire up event of SendCompleted
sc.SendCompleted += new SendCompletedEventHandler(sc_SendCompleted);
sc.SendAsync(mm,null);
void sc_SendCompleted(object sender, AsyncCompletedEventArgs e)
{ if(e.Cancelled)
{
MessageBox.Show(“Message sending is Cancelled”);
}
else if(e.Error != null)
{
MessageBox.Show(“Error to Send Email Error is:” + e.Error.ToString() );
}
else
{
MessageBox.Show(“Message sent Successfully”);
}
}
No comments:
Post a Comment