DotNet Send Mail
SendMail
public bool SendMail(string smtp, string t_port, string from, string pwd, string to, string subject, string bodytext, string displayName, bool ssl)
{
System.Net.Mail.SmtpClient client = new SmtpClient();
client.Host = smtp;
client.UseDefaultCredentials = true;
client.Timeout = 135000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Credentials = new System.Net.NetworkCredential(from, pwd);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Port = Convert.ToInt32(t_port);
System.Net.Mail.MailMessage message = new MailMessage(from, to);
message.From = new MailAddress(from, displayName);
message.Subject = subject;
message.Body = bodytext;
message.IsBodyHtml = true;
message.BodyEncoding = System.Text.Encoding.UTF8;
client.EnableSsl = ssl;
client.Credentials = new System.Net.NetworkCredential(from, pwd);
Regex reg = new Regex(@"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$");
try
{
if (reg.IsMatch(from) && reg.IsMatch(to))
{
client.Send(message);
return true;
}
else
return false;
}
catch (Exception ex)
{
return false;
}
}
{
System.Net.Mail.SmtpClient client = new SmtpClient();
client.Host = smtp;
client.UseDefaultCredentials = true;
client.Timeout = 135000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Credentials = new System.Net.NetworkCredential(from, pwd);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Port = Convert.ToInt32(t_port);
System.Net.Mail.MailMessage message = new MailMessage(from, to);
message.From = new MailAddress(from, displayName);
message.Subject = subject;
message.Body = bodytext;
message.IsBodyHtml = true;
message.BodyEncoding = System.Text.Encoding.UTF8;
client.EnableSsl = ssl;
client.Credentials = new System.Net.NetworkCredential(from, pwd);
Regex reg = new Regex(@"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$");
try
{
if (reg.IsMatch(from) && reg.IsMatch(to))
{
client.Send(message);
return true;
}
else
return false;
}
catch (Exception ex)
{
return false;
}
}