我正在尝试通过邮件服务器发送邮件(在 fatcow 中可用)。
Username: info@efernssolutions.com
SMTP Server: smtp.hostname.com
SMTP Port: 587
我使用以下代码发送邮件,
if (ModelState.IsValid)
{
MailMessage message = new MailMessage();
try
{
message.To.Add(new MailAddress("kishore.eferns@gmail.com"));
message.From = new MailAddress("info@efernssolutions.com");
message.Subject = "Test mail";
message.Body = "this is the mail sended through my c#.net program";
message.BodyEncoding = System.Text.Encoding.UTF8;
message.SubjectEncoding = System.Text.Encoding.UTF8;
SmtpClient client = new SmtpClient();
client.Port = 587;
client.Host = "smtp.hostname.com";
System.Net.NetworkCredential nc = new System.Net.NetworkCredential("info@efernssolutions.com", "password");// is u are using Gmail
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = nc;
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate);
client.Send(message);
}
catch (Exception ex)
{
;
}
}
当我使用 gmail 服务器时,代码工作正常,我收到了邮件。
但它不适用于我的电子邮件服务器。
我得到错误,
the remote certificate is invalid according to the validation procedure
有什么事情要做才能让它发挥作用吗?
请帮忙,
谢谢