码迷,mamicode.com
首页 > Windows程序 > 详细

C# 用QQ企业邮箱发邮件

时间:2015-05-05 18:38:36      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:

问题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

 

C# 用QQ企业邮箱发邮件

标签:

原文地址:http://www.cnblogs.com/wgscd/p/4479391.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!