2015-02-11 30 views
1

我試圖通過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> 
+0

它是正確的,你的發件人密碼代碼和配置之間的不同,還是僅僅是你編輯真實數據的地方? – 2015-02-11 15:25:11

+0

不,我只是修改真實的數據,我跳過,我會改正它 – dontknowathing 2015-02-11 15:46:45

回答

0

入住這https://www3.trustwave.com/support/kb/article.aspx?id=11849

  • 導航到控制面板。
  • 管理工具,然後本地安全策略。
  • 本地策略和安全選項。
  • 系統加密:使用符合FIPS的算法進行加密,散列和簽名。
  • 禁用該設置,然後單擊應用。
  • 重新啓動IIS
+0

我剛剛嘗試過,現在我得到了一個不同的錯誤,「發送電子郵件失敗」,內部的異常是「客戶端和服務器無法通信,因爲它們不具備通用算法「 – dontknowathing 2015-02-11 16:30:16

+0

我試過這個[link](http://blogs.msdn.com/b/winsdk/archive/2014/05/01/encountering-quot-the -client-and-server-can not-communicate-because-they-do-not-possess-a-common-algorithm-quot-or-sec-e-algorithm-mismatch-0x80090331.aspx)但我找不出來**密碼**是我的服務器使用 – dontknowathing 2015-02-11 17:38:06

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 = "[email protected]"; 
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();