我在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,异常异常) 在
答案 0 :(得分:0)
我会首先尝试不进行身份验证,以检查是否会产生不同的错误,并尝试不使用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;
}