/// This is the primery method try from the program
/// Latest & easiest method of sending an Email using ASP.NET
///
///
///
///
///
public static void sendMail(string to, string from, string subject, string body)
{
///Smtp config
SmtpClient client = new SmtpClient("smtp.gmail.com", 465);
// Edit password and username
client.Credentials = new NetworkCredential("kalit.sikka@gmail.com", "password");
client.EnableSsl = true;
///mail details
MailMessage msg = new MailMessage();
try
{
msg.From = new MailAddress(from);
msg.To.Add(to);
// msg.SubjectEncoding = System.Text.Encoding.UTF8;
msg.Subject = subject;
//msg.CC.Add();
msg.IsBodyHtml = true;
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.Body = body;
msg.Priority = MailPriority.Normal;
// Enable one of the following method.
client.Send(msg);
// or use the following alternative after enabling send mail asynchronous option in the global.asax
//object userState = msg;
//client.SendAsync(msg, userState);
}
catch (Exception exp)
{
///This runs the backup plan
SendMailAlt(to, from, subject, body);
}
}
good if it works, nice trick.
ReplyDelete