System.Net.Mail.SmtpClient.Send()超时SmtpException

时间:2015-01-07 10:32:51

标签: c# email

我想通过Email

发送GMail

我可以通过Gmail在家发送电子邮件

System.Net.Mail.SmtpClient.Send()使用相同的代码在公司的封闭网络中返回Timeout SmtpException

我打算向网络管理员询问此事。

网络管理员不知道gmail使用的地址/端口信息,因此在询问我尝试将[address:smtp.gmail.com, port:587]telnet连接成功之前,我必须知道需要检查的地址/端口连接。

还有更多要检查/打开网络地址/端口吗?

1 个答案:

答案 0 :(得分:0)

您需要使用EnableSsl = true

        static void Main(string[] args)
        {
            var client = new SmtpClient("smtp.gmail.com", 587)
            {
                Credentials = new NetworkCredential("myusername@gmail.com", "mypwd"),
                EnableSsl = true
            };
            client.Send("myusername@gmail.com", "myusername@gmail.com", "test", "testbody");
            Console.WriteLine("Sent");
            Console.ReadLine();
        }

FYI Gmail需要身份验证:

Outgoing Mail (SMTP) Server
requires TLS or SSL: smtp.gmail.com (use authentication)
Use Authentication: Yes
Port for TLS/STARTTLS: 587
Port for SSL: 465
相关问题