我正在尝试通过邮件服务器发送邮件(在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
还有什么可以让它发挥作用吗?
请帮忙,
谢谢
答案 0 :(得分:1)
首先,我会建议您检查服务器上是否正确安装了SSL证书