我想通過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