smtp 邮件发送请求有时失败
smtp email send request fails sometimes
我在 C# 中使用以下代码,
string Subject = "test12";
MailMessage mail = new MailMessage();
mail.To.Add(item.ToString());
mail.From = new MailAddress(EmailUserName);
mail.Subject = Subject;
mail.Body = PopulateBody();
mail.IsBodyHtml = true;
SmtpClient client = new SmtpClient(EmailHost, EmailPort);
client.EnableSsl = true;
NetworkCredential credentials = new NetworkCredential(EmailUserName, EmailPassword);
client.UseDefaultCredentials = false;
client.Credentials = credentials;
client.Send(mail);
我在 Client.send(mail) 方法中遇到错误
我尝试过的:
System.Security.Authentication.AuthenticationException: 调用 SSPI 失败,请参阅内部异常。 ---> System.ComponentModel.Win32Exception: 不支持请求的功能
--- 内部异常堆栈跟踪结束 ---
在 System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken 消息,AsyncProtocolRequest asyncRequest,Exception 异常)
在
我会先尝试不进行身份验证,以检查是否会出现不同的错误,然后再尝试不使用 ssl。
protected bool NotifyByMail(string server, string strFrom, string strTo, string strSubject, string strBodyText, bool isBodyTextHtml = false)
{
if (string.IsNullOrEmpty (server)
|| string.IsNullOrEmpty (strFrom)
|| string.IsNullOrEmpty (strTo)
|| string.IsNullOrEmpty (strSubject)
|| string.IsNullOrEmpty (strBodyText))
return false;
try {
MailAddress from = new MailAddress (strFrom);
MailAddress to = new MailAddress (strTo);
MailMessage message = new MailMessage (from, to);
message.Subject = strSubject;
message.Body = strBodyText;
message.IsBodyHtml = isBodyTextHtml;
SmtpClient client = new SmtpClient (server);
// Include credentials if the server requires them.
//client.Credentials = new System.Net.NetworkCredential ("********", "*******");// System.Net.CredentialCache.DefaultNetworkCredentials;
client.Send (message);
return true;
}
catch (Exception exception) {
// TODO ErrorHandling
}
return false;
}
我在 C# 中使用以下代码,
string Subject = "test12";
MailMessage mail = new MailMessage();
mail.To.Add(item.ToString());
mail.From = new MailAddress(EmailUserName);
mail.Subject = Subject;
mail.Body = PopulateBody();
mail.IsBodyHtml = true;
SmtpClient client = new SmtpClient(EmailHost, EmailPort);
client.EnableSsl = true;
NetworkCredential credentials = new NetworkCredential(EmailUserName, EmailPassword);
client.UseDefaultCredentials = false;
client.Credentials = credentials;
client.Send(mail);
我在 Client.send(mail) 方法中遇到错误
我尝试过的:
System.Security.Authentication.AuthenticationException: 调用 SSPI 失败,请参阅内部异常。 ---> System.ComponentModel.Win32Exception: 不支持请求的功能 --- 内部异常堆栈跟踪结束 --- 在 System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken 消息,AsyncProtocolRequest asyncRequest,Exception 异常) 在
我会先尝试不进行身份验证,以检查是否会出现不同的错误,然后再尝试不使用 ssl。
protected bool NotifyByMail(string server, string strFrom, string strTo, string strSubject, string strBodyText, bool isBodyTextHtml = false)
{
if (string.IsNullOrEmpty (server)
|| string.IsNullOrEmpty (strFrom)
|| string.IsNullOrEmpty (strTo)
|| string.IsNullOrEmpty (strSubject)
|| string.IsNullOrEmpty (strBodyText))
return false;
try {
MailAddress from = new MailAddress (strFrom);
MailAddress to = new MailAddress (strTo);
MailMessage message = new MailMessage (from, to);
message.Subject = strSubject;
message.Body = strBodyText;
message.IsBodyHtml = isBodyTextHtml;
SmtpClient client = new SmtpClient (server);
// Include credentials if the server requires them.
//client.Credentials = new System.Net.NetworkCredential ("********", "*******");// System.Net.CredentialCache.DefaultNetworkCredentials;
client.Send (message);
return true;
}
catch (Exception exception) {
// TODO ErrorHandling
}
return false;
}