我正在尝试通过我的C#应用程序发送电子邮件,但每次我尝试发送电子邮件时,都会发生错误,说“对sspi的调用失败”,当我看到内部的例子,它说“客户端和服务器无法通信,因为他们没有共同的算法”
我的代码是:
try
{
var fromAddress = new MailAddress("sender@domain.com", "Sender");
var toAddress = new MailAddress("receiver@domain.com", "Receiver");
const string fromPassword = "Pass123";
const string subject = "Prueba";
const string body = "Prueba body";
var smtp = new SmtpClient
{
Host = "smpt.domain.com",
Port = 25,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new System.Net.NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body,
DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure,
BodyEncoding = UTF8Encoding.UTF8
})
{
smtp.Send(message);
}
}
catch (Exception exc)
{
MessageBox.Show(string.Format("Error: {0}", exc.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
在我的App.config上我有类似的东西:
<system.net>
<mailSettings>
<smtp from="sender@domain.com">
<network host="smtp.domain.com" port="25" userName="sender@domain.com" password="Pass123" defaultCredentials="true" />
</smtp>
</mailSettings>
</system.net>
答案 0 :(得分:0)
选中此https://www3.trustwave.com/support/kb/article.aspx?id=11849
答案 1 :(得分:0)
最后我只是放弃使用SmtpClient和MailMessage,我使用的是Outlook MailItem
Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
oMsg.To = "correo@gmail.com";
oMsg.Subject = "Prueba";
oMsg.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML;
oMsg.HTMLBody = "<html><body>";
oMsg.HTMLBody += string.Format("<p>El dato {0}", var1);
oMsg.HTMLBody += string.Format("se guardo en la <a href='{0}'>dirección</a>.</p> </br> <p>Saludos.</p> </body></html>", path);
oMsg.Display(false);
((Microsoft.Office.Interop.Outlook._MailItem)oMsg).Send();