问题
I'm trying to send an email via my C# application, but every time i try to send the email, an error occurs, saying "A call to sspi failed", when i look at the inner exeption it says something like "The client and server cannot communicate, because they do not possess a common algorithm"
My code is this:
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);
}
And on my App.config i have something like:
<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>
回答1:
Check this https://www3.trustwave.com/support/kb/article.aspx?id=11849
- Navigate to Control Panel.
- Administrative Tools and then Local Security Policy.
- Local Policies and Security Options.
- System Cryptography: Use FIPS compliant algorithms for encryption, hashing, and signing.
- Disable the setting, and then click Apply.
- Restart the IIS
回答2:
At the end i just give up with using SmtpClient and MailMessage, i used 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();
来源:https://stackoverflow.com/questions/28457975/common-algorithm-issue-while-trying-to-send-an-email-using-c-sharp