Monday, April 2, 2012

NICE MAIL SERVER CODE for asp .net bt GMAIL SERVER...

This code you can use for Forget Password/ Mailing Form....Etc


public bool SendMail(string gMailAccount, string password, string to, string subject)
{
try
{
//Attachment mailAttachment = new Attachment(getfile);
NetworkCredential loginInfo = new NetworkCredential(gMailAccount, password);
MailMessage msg = new MailMessage();
msg.From = new MailAddress(gMailAccount);
msg.To.Add(new MailAddress(to));
msg.Subject = "Gifttoindia.co.in Password has been received";
msg.Body = "Your password is: " + subject;
msg.IsBodyHtml = true;
//msg.Attachments.Add(mailAttachment);
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = loginInfo;
client.Send(msg);

return true;
}
catch (Exception)
{
return false;
}

}

No comments:

Post a Comment