2015-03-13 155 views
-2

我想發送自動電子郵件時,有一些機構在我的網站上註冊。每當我在網站(本地服務器)上註冊時,都沒有例外。我還添加了使用system.Net.Mail和web.Config腳本a。 以下是我的一段ASP.NET代碼:無法發送電子郵件與c#

public void SendWelcomeMail() 
    { 
     string EmailTO = TextBoxEmail.Text; 
     string EmailFrom = "[email protected]"; 
     string Pass = TextBoxPassword.Text; 
     try 
     { 
      MailMessage message = new MailMessage(); 
      message.From = new MailAddress(EmailFrom); 

      message.To.Add(new MailAddress(EmailTO)); 

      message.Subject = "Welcome"; 
      message.Body = "You are now registered with your email ID "+EmailTO; 
      message.Body = "Your Password is "+Pass; 
      SmtpClient client = new SmtpClient(); 
      client.Send(message); 
     } 
     catch 
     { 
      Response.Write("Sorry there is an exception. Some thing must be wrong"); 
     } 
} 
+4

既然你沒有指定參數爲SmtpClient()構造函數,它正在尋找主機,端口和憑證在應用程序設置或系統配置文件中。你記得配置其中之一嗎? – 2015-03-13 18:13:31

+0

不,我只是完全忘了設置主機,在SmtpClient構造函數中添加要添加的其他內容。我明白爲什麼我無法發送電子郵件。謝謝。 – 2015-03-13 18:28:19

回答