一、处理25端口
①、换用端口
2、云服务器可用端口。
1、可用端口(465、587)。
②、使用(465、587)端口问题
1、错误信息:The SMTP server requires a secure connection or the client was not authenticated.
2、错误信息: Bad sequence of commands. The server response was: Error: need EHLO and AUTH first
③、完整代码(处理及解决)
1、禁用默认凭证、启用ssl。
/// <summary>
/// 发送邮件
/// </summary>
/// <returns></returns>
public async Task SendAsync()
{
MailMessage mail = new MailMessage();
mail.To.Add(new MailAddress("apricot@qq.com"));
mail.Body = "so far ~";
Mail.SmtpClient smtp = new Mail.SmtpClient();
mail.From = new MailAddress("1764564459@qq.com", "1764564459");
smtp.UseDefaultCredentials = false;//禁用默认凭证
smtp.EnableSsl = true;//启用ssl
smtp.Host = "smtp.exmail.qq.com";
smtp.Port = 587;
smtp.Credentials = new NetworkCredential("1764564459@qq.com", "password");
await smtp.SendMailAsync(mail);
}
二、参考