Saturday, March 16, 2013

Send email using C#

Simple code to send the email gmail SMTP.


Add Namespaces :
using System.Net.Mail;
 
Code :
 
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"); //Enter your SMTP address

mail.From = new MailAddress("your_emailID@gmail.com");
mail.To.Add("to_address");
mail.Subject = "Test EMail";
mail.Body = "Test SMTP mail from GMAIL";

SmtpServer.Port = 25;
SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail); 

1 comment: