我已经尝试了好几天了。 '真的可以使用一些帮助! 将电子邮件(从MVC应用程序)发送到“ mail.yahoo.com”需要使用端口465(根据其规格)和SSL / TLS。 显然,这需要隐式SSL,而Microsoft仅支持显式SSL。因此,我导入了EASendMail,它被告知可以处理使用端口465所需的隐式SSL连接。我仍然遇到超时错误...(连接失败)。如果有人指出我在哪里搞砸,将不胜感激。
class SendMail
{
static public void Go()
{
try
{
SmtpMail oMail = new SmtpMail("TryIt");
// Set sender email address, please change it to yours
oMail.From = "xxxx@att.net";
// Set recipient email address, please change it to yours
oMail.To = "xxxx@att.net";
oMail.Sender = "xxxx@att.net";
// Set email subject
oMail.Subject = "test email from c#, ssl, 465 port";
// Set email body
oMail.TextBody = "this is a test email sent from c# project, do not reply";
// Your SMTP server address
SmtpServer oServer = new SmtpServer("mail.yahoo.com");
// User and password for ESMTP authentication, if your server doesn't require
// User authentication, please remove the following codes.
oServer.User = "xxxx@att.net";
oServer.Password = "xxxxxxxx";
// Set 465 SMTP port
oServer.Port = 465;
// Enable SSL connection
oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;
Debug.WriteLine("start to send email ...");
SmtpClient oSmtp = new SmtpClient();
oSmtp.SendMail(oServer, oMail);
Debug.WriteLine("email was sent successfully!");
}
catch (Exception ep)
{
Debug.WriteLine("failed to send email with the following error:");
Debug.WriteLine(ep.Message);
}
}
}