2013-02-20 80 views

回答

0

我假設你的代碼沒有問題。我想這是一個配置問題,即SMTP服務器配置爲不發送電子郵件到不屬於公司域的地址。如果是這樣,您需要與您的Windows /網絡團隊覈對以確認在SMTP服務器級別應用的配置。

1

我已解決此問題。要使用此代碼,您需要添加命名空間使用System.Web.Mail;

源代碼:

MailMessage mail = new MailMessage(); 

mail.To = "[email protected]"; 

mail.From = "[email protected]"; 

mail.Subject = "Email test."; 

mail.Body = "Your body text here"; 

mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication 

mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "my_username_here"); //set your username here 

mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "super_secret");  //set your password here 

SmtpMail.SmtpServer = "127.0.0.1"; 

SmtpMail.Send(mail); 

//你需要本地主機地址添加到IIS管理器。 轉到IIS管理器 - >默認SMTP服務器 - >屬性 - >訪問 - >繼電器 - >只允許從下面的列表中 - >添加 - > 127.0.0.1 - >點擊確定

相關問題