这是我的代码:
public static void SendMail(string to, string subject, string body, string mailTitle)
{
MailMessage mail = new MailMessage();
mail.Subject = subject;
mail.From = new MailAddress("***", mailTitle);
mail.To.Add(to);
mail.Body = body;
mail.IsBodyHtml = true;
SmtpClient c = new SmtpClient("leavingstone.net", 25);
c.EnableSsl = false;
c.Credentials = new NetworkCredential("***", "***");
c.Send(mail);
}
有时会发送邮件,有时则不会发送邮件 - 但不会抛出任何错误。
是否可以通过代码解决问题,还是主机失败?
答案 0 :(得分:0)
试试我的SMTP代码,非常适合我!
SmtpClient smtp = new SmtpClient();
smtp.Host = "mail.domain.com";
smtp.EnableSsl = Convert.ToBoolean("false");
NetworkCredential NetworkCred = new NetworkCredential();
NetworkCred.UserName = "no-reply@domain.com";
NetworkCred.Password = "**************";
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = Convert.ToInt16(25);
smtp.Send(mm);