C# smtp.gmail.com:根据验证过程,远程证书无效:其他服务器工作正常
无法使用Google smtp.gmail.com邮件服务器发送电子邮件。同样的代码适用于outlook.office365.com邮件服务器。我搜索并尝试了在这个网站上找到的所有代码片段。下面是代码当前状态的快照C# smtp.gmail.com:根据验证过程,远程证书无效:其他服务器工作正常,c#,asp.net,smtp,gmail,C#,Asp.net,Smtp,Gmail,无法使用Google smtp.gmail.com邮件服务器发送电子邮件。同样的代码适用于outlook.office365.com邮件服务器。我搜索并尝试了在这个网站上找到的所有代码片段。下面是代码当前状态的快照 try { string sSMTPServer = WebConfigurationManager.AppSettings["SMTPServer"]; string sSMTPUsername = WebConfigurationManager.AppSettin
try
{
string sSMTPServer = WebConfigurationManager.AppSettings["SMTPServer"];
string sSMTPUsername = WebConfigurationManager.AppSettings["SMTPUsername"];
string sSMTPPassword = WebConfigurationManager.AppSettings["SMTPPassword"];
System.Net.Mail.SmtpClient emailClient = new System.Net.Mail.SmtpClient();
emailClient.Host = sSMTPServer;
emailClient.Credentials = new System.Net.NetworkCredential(sSMTPUsername, sSMTPPassword);
emailClient.UseDefaultCredentials = true;
emailClient.DeliveryMethod = SmtpDeliveryMethod.Network;
emailClient.Port = 587; //produces "the remote certificate is invalid according to the validation procedure."
//emailClient.Port = 465; produces "failure sending email" error
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
emailClient.EnableSsl = true;
emailClient.Send(mailmessage);
emailErrorHandler.errorThrown = false;
emailErrorHandler.message = "Email Sent Successfully!";
}
catch (Exception ex)
{
emailErrorHandler.errorThrown = true;
emailErrorHandler.message = "error: " + ex.Message;
}
希望这个问题对你有帮助!我们无法使用端口25,必须是安全端口587或465