一“Bad sequence of commands. The server response was: Error: need EHLO and AUTH first !”
发送其他邮箱正常,但发qq邮箱时会出现上面的异常:
把这个属性EnableSsl 设为true即可。
二:“remote certificate is invalid according to the validation procedure.”
在一中开启ssl验证后,在有些服务器上上可能会出现上面异常,数字证书异常,解决方法,先看下服务器的时间是否正常,然后我们在C#代码中对这个异常做处理:
如下代码,在连接smtp前 RemoteCertificateValidate 捕获处理证书的异常:
{
ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidate;
SmtpClient client = new SmtpClient(smtp);
client.EnableSsl = true;
client.UseDefaultCredentials = true;
client.Credentials = new System.Net.NetworkCredential(fromID, fromPass);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Send(message);
message.Dispose();
}
public bool RemoteCertificateValidate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{
return true;
}
发送其他邮箱正常,但发qq邮箱时会出现上面的异常:
把这个属性EnableSsl 设为true即可。
二:“remote certificate is invalid according to the validation procedure.”
在一中开启ssl验证后,在有些服务器上上可能会出现上面异常,数字证书异常,解决方法,先看下服务器的时间是否正常,然后我们在C#代码中对这个异常做处理:
如下代码,在连接smtp前 RemoteCertificateValidate 捕获处理证书的异常:
{
ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidate;
SmtpClient client = new SmtpClient(smtp);
client.EnableSsl = true;
client.UseDefaultCredentials = true;
client.Credentials = new System.Net.NetworkCredential(fromID, fromPass);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Send(message);
message.Dispose();
}
public bool RemoteCertificateValidate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{
return true;
}