This article explains how to send asynchronous mail using a SmtpClient.SendCompleted Event and a SmtpClient.SendAsyncCancel Method in ASP.NET 4.5 for sending the specified message to an SMTP server for delivery as an asynchronous operation.
So, let's proceed with the following procedure:
- Create an Asynchronous Page ASP.NET web page
- Create a SmtpClient.SendCompleted Event and SmtpClient.SendAsyncCancel Method
Creating an Asynchronous Page
Create a new project using "File" -> "New" -> "Project..." then select web "ASP.NET Web Forms Application". Name it "SendMailAsync".
Next, create the code-behind as follows: The first step is to build an asynchronous page and setting the Async attribute in the Page directive to true, as shown here:
<%@ Page Language="C#" Async="true" %>
Now, in the code behind file SendMail.aspx use the following code.
SendMail.aspx
Create a SmtpClient.SendCompleted Event and SmtpClient.SendAsyncCancel Method
Now, in the code behind file “SendMail.aspx.cs “ use the following code.
SendMail.aspx.cs
Now run the page, it will look like this:
Now, show in the Message box “Email sent successfully”.
I hope this article is useful. If you have any other questions then please provide your comments in the following.