我想通过gmail发送电子邮件,但此代码不起作用,导致连接超时错误。如果我做端口“587”它给了这个错误:Gmail发送电子邮件超时
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
string email = // email
string password = // password
string smtp = // smtp.gmail.com
int port = // 465
var from = new MailAddress(email, "");
var to = new MailAddress(message.Destination);
var client = new SmtpClient()
{
Host = smtp,
Port = port,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(email, password)
};
var mail = new MailMessage(from, to)
{
Subject = subject,
Body = body,
IsBodyHtml = true
};
return client.SendMail(mail);
}
您是否能够从您正在运行程序的计算机以其他方式连接到smtp.gmail.com:465?例如,通过telnet到这个地址/端口。 – 2014-09-19 12:42:30
它也不适用于Azure。 – Barte 2014-09-19 12:46:29