Mail seding in c# using gmail Account in asp.net.
below is a code for sending mail using your gmail account...
MailMessage msg = new MailMessage();
SmtpClient mailobj = new SmtpClient();
msg.From = new MailAddress("gmailid@gmail.com");
msg.To.Add(new MailAddress("sendmailto@gmail.com"));
msg.IsBodyHtml = true;
msg.Body = "Hi, dear <br/><br/>Your Registration completed.Thank You. ";
msg.Subject = "Email subject...";
msg.IsBodyHtml = true;
msg.Priority = MailPriority.High;
mailobj.Host = "smtp.gmail.com";
mailobj.Port = 587;
mailobj.EnableSsl = true;
mailobj.Credentials = newSystem.Net.NetworkCredential("gmailid@gmail.com", "gmailpassword");
try
{
mailobj.Send(msg);
Response.Write("Your mail is sended");
}
catch (Exception ex)
{
Response.Write("The error has occured during sending mail => "+ ex);
}
Thats it... replace your gmail account id and password in above code where its indicated,
No comments:
Post a Comment