我試圖通過C#應用程序發送電子郵件,但每次嘗試發送電子郵件時都會發生錯誤,並說「對sspi的調用失敗 」當我看到內exeption它說,像‘客戶端和服務器不能溝通,因爲他們不具備一個共同的算法’嘗試使用C#發送電子郵件時常見算法問題
我的代碼是這樣的:
try
{
var fromAddress = new MailAddress("[email protected]", "Sender");
var toAddress = new MailAddress("[email protected]", "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="[email protected]">
<network host="smtp.domain.com" port="25" userName="[email protected]" password="Pass123" defaultCredentials="true" />
</smtp>
</mailSettings>
</system.net>
它是正確的,你的發件人密碼代碼和配置之間的不同,還是僅僅是你編輯真實數據的地方? – 2015-02-11 15:25:11
不,我只是修改真實的數據,我跳過,我會改正它 – dontknowathing 2015-02-11 15:46:45