Thursday, January 1, 2009

Send Email From Gmail Account using C#,VB,ASP.NET

MailMessage mailmsg = new MailMessage();
mailmsg.From = new MailAddress("your gmail ID");
mailmsg.To.Add(new MailAddress("tomailaddress"));
mailmsg.Subject = sub ;

StringBuilder body = new StringBuilder();

body.AppendLine( Subject );

mailmsg.Body = body.ToString();

mailmsg.IsBodyHtml = true;
SmtpClient Sc = new SmtpClient();
Sc.EnableSsl = true;

Sc.Credentials = new System.Net.NetworkCredential(Your gmail id, "PWD");

try
{

Sc.Send(mailmsg);
Mess = "Mail Send Successgully.";
}
catch (Exception ex)
{
Mess = ex.Message.ToString() ;
}
}
}

No comments: