C# 用QQ企业邮箱发邮件

问题System.Net.Mail下的SmtpClient来发送邮件,而System.Net.Mail only仅支持Explicit SSL

不要465端口,用25,不用EnableSsl = true;

    {
        static void Main(string[] args)
        {
            SmtpClient client = new SmtpClient();
            client.Host = "smtp.exmail.qq.com";
            client.Port = 25;
           // client.Port = 465;
          //  client.EnableSsl = true;
            client.Timeout = 10000;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = false;
            client.Credentials = new System.Net.NetworkCredential("test@ms.com", "1234567890");
            MailMessage mm = new MailMessage("test@ms.com", "user1@ms.com", "test", "test");
            mm.BodyEncoding = UTF8Encoding.UTF8;
            mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
            client.Send(mm);
        }
    }

最后在配置TFS邮件通知设置的时候端口改用25,不选择SSL,顺利解决问题。

SmtpClient发送邮件超时的异常参考:

http://blogs.msdn.com/b/webdav_101/archive/2008/06/02/system-net-mail-with-ssl-to-authenticate-against-port-465.aspx

上一篇:jQuery插件开发的五种形态小结


下一篇:spring boot 启动遇到报错:Failed to configure a DataSource