In this tutorial you will learn that sending an email with an attachment using ASP.NET 4.0 and C# is actually very simple and easy to accomplish.

First, you will need to import the System.Net.Mail namespace.

The System.Net.Mail namespace contains the SmtpClient and MailMessage Classes that we need in order to send the email and the message attachment.

The front end .aspx page will use a table to hold all the information. We will be using input fields to accept all the information and declare the variables for our codebehind:

We use the btnSubmit_Click event to do the work. To access the code behind go into design view and double click on the button. This should allow you to enter the code behind for the button.

We then call the emailClient.Send to send the message using the variables from our ASP.NET coded page. The txtAttachmentPath.Text Texbox provides the path to the file to attach to the email message. For this tutorial we chose to simply have the user type the path manually, but you can experiment on different ways to accomplish this effect.

In this tutorial we learned about Sending Email with Attachment using ASP.NET 4.0 and C#. While this tutorial was fairly simple, it is left up to you to expand upon the ideas and develop some awesome applications.

Download Source Files