我有一個webform,有人可以設置一個帳戶 - 我想給他們發送電子郵件確認。如何從我的C#codebehind發送電子郵件 - 獲取System.Net.Mail.SmtpFailedRecipientException
我正在使用的代碼:
// Create e-mail message
MailMessage mm = new MailMessage();
mm.From = new MailAddress("[email protected]", "Our Organisation");
mm.To.Add(new MailAddress("[email protected]", "Web User"));
mm.Subject = "Confirmation";
mm.Body = "You are now registered test";
mm.IsBodyHtml = true;
// Send e-mail
sc = new SmtpClient();
NetworkCredential basicAuthenticationInfo = new NetworkCredential(「[email protected]」, 「ourorganisationemailPassword」);
sc.Credentials = basicAuthenticationInfo;
sc.UseDefaultCredentials = false;
sc.Send(mm);
的web.config:
<system.net>
<mailSettings>
<smtp>
<network host="[email protected]" port="9999" userName="[email protected]" password="OurOrganisationEmailPassword"/>
</smtp>
</mailSettings>
</system.net>
但得到:
System.Net.Mail.SmtpFailedRecipientException was caught
HResult=-2146233088
Message=Mailbox unavailable. The server response was: Authentication is required for relay
Source=System
FailedRecipient=<[email protected]>
看起來像它希望爲網絡用戶登錄信息我想寄給的地址。我怎樣才能修改這個併發送這樣的確認電子郵件,比如所有其他商業公司都這麼做?
在的NetworkCredential,你有沒有嘗試使用真實的用戶名,而不是用戶的電子郵件?即「OurOrganisationEmail」。 (你也應該使用代碼或配置,但不能同時使用) – Fabske 2013-02-25 14:02:48