Home / ASP.NET Wiki / .NET Framework Essentials / Send email with smtp authentication using ASP.NET 3.5 / how to send email with attachment from local machine

how to send email with attachment from local machine

 Rate It (7)

using System.Net.Mail;

public partial class SUPER_mail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button4_Click(object sender, EventArgs e)
    {
      
      
        MailMessage msg = new MailMessage();
        msg.From = new MailAddress("your gmail id");
        msg.To.Add(TextBox2.Text);
        msg.Subject = TextBox3.Text;
        msg.Body = TextBox4.Text;
 if (FileUpload1.HasFile)
        {
            FileUpload1.SaveAs("C:\\Program Files (x86)\\Common Files\\microsoft shared\\DevServer\\10.0\\" + FileUpload1.FileName);
            Label3.Text = FileUpload1.FileName;
  msg.Attachments.Add(new Attachment(Label3.Text));
        }

     
        SmtpClient smt = new SmtpClient();
        smt.Send(msg);
        Label2.Text = "mail sucessfully transfer";
    }
}

 

//inside the web.config file

<system.net >
    <mailSettings >
      <smtp >
        <network host ="smtp.gmail.com"  password ="your gmail password" userName ="your gmail id"/>
      </smtp>
    </mailSettings>
  </system.net>

Revision number 1, Thursday, November 10, 2011 10:25:10 PM by tarunsaini

Comments

Related Articles

Sending Email in Asp.net

Sending email is very common in Asp.net application. In most of asp.net applications I was asked to send email to client or admin etc. Meanwhile, almost always I was asked to change content of email many times. Like change a sentence, put space between sentences

Custom Error messages using Global.asax and Membership model

Scenario: Using ASP.NET membership model to display custom error messages to general users of a website. Send an email to a Webmaster with all the details of such an exception. Also in development environment only detailed exceptions are to be displayed and

RegularExpressionValidator

The RegularExpressionValidator control confirms that the entry matches a pattern defined by a regular expression. This type of validation allows you to check for predictable sequences of characters, such as those in social security numbers, e-mail addresses

Send email with smtp authentication using ASP.NET 3.5

Following Codes demonstrates how to send an email with SMTP Authentication using ASP.NET 3.5 using System.Net.Mail MailMessage msgMail = new MailMessage(); MailMessage myMessage = new MailMessage(); myMessage.From = new MailAddress("sender's email"

Shortcuts

Table of Contents

Top Wiki Contributors

(last 30 days)

  1. francissvk (1)
  2. deepeshsp (1)