Introduction
This article explains how to send an email with attachments using SmtpClient.SendAsync. My previous article explained sending Asynchronous Emails in ASP.NET 4.5 I will now explain how to implement send asynchronous mail with an attachment in ASP.NET 4.5.
Creating an Asynchronous Page
Create a new project using "File" -> "New" -> "Project..." then select web "ASP .Net Web Forms Application". Name it " SendMailAsyncAttachment ".
Next, create the code-behind as follows: The first step to building an asynchronous page is setting the Async attribute in the Page directive to true, as shown here:
<%@ Page Language="C#" Async="true" %>
Now, in the code behind file SendMailAttach.aspx use the following code.
SendMailAttach.aspx
Create a SmtpClient.SendCompleted Event and SmtpClient.SendAsyncCancel Method and attachment
Now, in the code behind file “SendMailAttach.aspx.cs “ use the following code.
SendMailAttach.aspx.cs
Now run the page, it will look like this:
Now, show in the Message box “Email sent successfully”.
Now, see the following screen: SendMailAsync with Attachment.
I hope this article is useful. If you have any other questions then please provide your comments in the following.