我已经在somee.com上托管了我的MVC项目。 电子邮件功能在那里不起作用。它在我的本地系统中运行良好。 提出了支持票,但没有回应。
记录的错误是:
ERROR TYPE : System.Net.Mail.SmtpException
ERROR MESSAGE : Failure sending mail.
INNER EXCEPTION MESSAGE : Unable to read data from the transport connection: net_io_connectionclosed.
,代码为:
var fromAddress = new MailAddress("myname@gmail.com", "My Name");
var toAddress = new MailAddress("validemail@gmail.com", "");
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, SmtpPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = emailSubject,
Body = emailBody,
IsBodyHtml = true,
BodyEncoding = Encoding.UTF8,
SubjectEncoding = Encoding.UTF8
})
{
//turning the security off for testing
ServicePointManager.ServerCertificateValidationCallback = delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{ return true; };
smtp.Send(message);
}
我还托管了Azure免费订阅。它在那里也不起作用。并记录相同的错误。
我想在启用网站之前对其进行测试。因为是免费/试用版订阅,所以出现此问题吗? 要么 在托管在服务器上时,应该更改我的代码以使其正常工作。