Wednesday, April 14, 2010

how to send email from .Net using gmail account

SmtpClient client = new SmtpClient("smtp.gmail.com");
client.Port = 587;
client.Credentials = new NetworkCredential("youname", "password");

client.EnableSsl = true;
MailMessage message = new MailMessage(
new MailAddress("To@gmail.com", "John"), //To
new MailAddress("CC@gmail.com", "Smith")); //CC
message.Bcc.Add(new MailAddress("BCC@com.com"));
message.Subject = "....";
message.Body = "body";

Attachment att = new Attachment(@"c:\abc.cs");
message.Attachments.Add(att);c

client.Send(message);