/// <summary>
/// Send Mail
/// </summary>
/// <param name="subject"></param>
/// <param name="message"></param>
/// <param name="toEmailId"></param>
/// <modifiedby></modifiedby>
/// <modifieddate></modifieddate>
public static bool SendMail(string subject, string message, string toEmailId)
{
if ((toEmailId != string.Empty))
{
SmtpClient client = new SmtpClient();
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = Convert.ToBoolean(ConfigurationManager.AppSettings["EnableSsl"]);
client.Host = ConfigurationManager.AppSettings["SmtpHost"];
client.Port = Convert.ToInt32(ConfigurationManager.AppSettings["SmtpPort"]);
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["SmtpEmail"], ConfigurationManager.AppSettings["SmtpPassword"]);
client.UseDefaultCredentials = false;
client.Credentials = credentials;
MailMessage msg = new MailMessage();
//msg.Priority = MailPriority.High;
msg.From = new MailAddress(ConfigurationManager.AppSettings["SmtpEmail"]);
string to = toEmailId;
msg.To.Add(new MailAddress(to));
msg.IsBodyHtml = true;
msg.Subject = subject;
msg.Body = message;
try
{
client.Send(msg);
return true;
}
catch
{
return false;
}
}
else
{
return false;
}
}
/// Send Mail
/// </summary>
/// <param name="subject"></param>
/// <param name="message"></param>
/// <param name="toEmailId"></param>
/// <modifiedby></modifiedby>
/// <modifieddate></modifieddate>
public static bool SendMail(string subject, string message, string toEmailId)
{
if ((toEmailId != string.Empty))
{
SmtpClient client = new SmtpClient();
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = Convert.ToBoolean(ConfigurationManager.AppSettings["EnableSsl"]);
client.Host = ConfigurationManager.AppSettings["SmtpHost"];
client.Port = Convert.ToInt32(ConfigurationManager.AppSettings["SmtpPort"]);
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["SmtpEmail"], ConfigurationManager.AppSettings["SmtpPassword"]);
client.UseDefaultCredentials = false;
client.Credentials = credentials;
MailMessage msg = new MailMessage();
//msg.Priority = MailPriority.High;
msg.From = new MailAddress(ConfigurationManager.AppSettings["SmtpEmail"]);
string to = toEmailId;
msg.To.Add(new MailAddress(to));
msg.IsBodyHtml = true;
msg.Subject = subject;
msg.Body = message;
try
{
client.Send(msg);
return true;
}
catch
{
return false;
}
}
else
{
return false;
}
}
No comments:
Post a Comment