有时不发送 C# 邮件,但不引发错误

本文关键字:错误 邮件 | 更新日期: 2023-09-27 18:30:26

这是我的代码:

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);
}
有时

发送邮件,有时不发送 - 但没有抛出错误。

是否可以从代码中解决问题,还是主机失败?

有时不发送 C# 邮件,但不引发错误

试试我的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);