Sending email with attachments from C#

In many cases you may required to send emails using ASP.NET. You can have all the classes required to send an email in the System.Net.Mail namespace. You can send an email from ASP.NET as follows :

First you have to add these namespaces to your code behind file:

1. using System.Net;
2. using System.Net.Mail;

Then write the following method

public void email_send()
    MailMessage mail = new MailMessage();
    SmtpClient SmtpServer = new SmtpClient("");
    mail.From = new MailAddress("your");
    mail.Subject = "Test Mail - 1";
    mail.Body = "mail with attachment";

    System.Net.Mail.Attachment attachment;
    attachment = new System.Net.Mail.Attachment("c:/textfile.txt");

    SmtpServer.Port = 587;
    SmtpServer.Credentials = new System.Net.NetworkCredential("your", "your password");
    SmtpServer.EnableSsl = true;



Using the above you can send attachemebts also. Hope this helps :-)