ASp.Net day

Micro blog

C# Send email

June 01
by Satalaj 1. June 2009 11:10

Send email using your SMTP and SMTP credentials. Here is code for snding email.


 protected void Button6_Click(object sender, EventArgs e)

 { 
    System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();  
    // instantiate message object System.Net.Mail.
    MailAddress address = new System.Net.Mail.MailAddress("from.mail@mail.com","From Mail display name");
    msg.From = address;
    msg.To.Add(
satalaj.more@sat.com);
    msg.Subject = "HELLO TEST";msg.Body = "HELLO SDFSF";
    System.Net.Mail.SmtpClient sc = new System.Net.Mail.SmtpClient();  
    // instantiate smtp object sc.Host = "my_SMTP_address";  
    // your smtp host
    sc.Port = 25;  // your smtp port
    System.Net.NetworkCredential nc = new System.Ne t.NetworkCredential(); 
    // your network credentials object
    nc.UserName =
your.name@yourdomain;
    nc.Password = "pasword";
    sc.Credentials = nc;     // pass network credentials to smtp
    sc.Send(msg);  / / paas message to smtp  and send and email.
}

About Satalaj

My name is Satalaj. I'm 2010 asp.net MVP. I write technical stuff here. www.satalaj.com

Ads by Lake Quincy Media

The best inline translator

Live lookup to see what asp.net developers are searching