事务失败。 服务器响应为:DT:SPM 163 smtp8


Posted on September 14, 2019


使用c#发送邮件,使用的是163的邮箱,调试时出现事务失败。 服务器响应为:DT:SPM 163 smtp8,网上找了很多方法没有解决,最后CC添加了发件人即可解决,原因不明,猜测和163的垃圾邮件策略有关。

另外,也发现和网络IP有关,平时用的长城宽带,经常被网易封杀,换成手机热点调试就好了,看来长城宽带还是不行呀。

public static void SendWeekReportEmail(string showname, string recipient, string subject, 
List<string> cc, string body, bool isBodyHtml, string file)
{
    string sender = "123@163.com";
    string pwd = "1233";//授权码
    MailMessage myEmail = new MailMessage();
    myEmail.From = new MailAddress(sender, showname);
    myEmail.To.Add(recipient);

    foreach (string c in cc)
    {
        myEmail.CC.Add(c);
    }

    myEmail.CC.Add(sender);

    myEmail.Subject = subject;
    myEmail.IsBodyHtml = isBodyHtml;
    //附件
    myEmail.Attachments.Add(new Attachment(file));
    myEmail.Body = body;
    myEmail.BodyEncoding = Encoding.UTF8;
    myEmail.Priority = MailPriority.Normal;
    myEmail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;

    SmtpClient smtp = new SmtpClient();
    smtp.UseDefaultCredentials = false;
    smtp.Credentials = new NetworkCredential(sender, pwd);
    smtp.Port = 25;
    smtp.Host = "smtp.163.com";
    smtp.EnableSsl = true;
    try
    {
        smtp.Send(myEmail);
    }
    catch (Exception e)
    {
        throw new Exception(e.Message);
    }
}

标签:N/A

 

微信扫码联系
微信扫码联系