2011-12-19 125 views
0

我一直在努力爭取使用Godaddy發送郵件的正確語法。任何幫助,將不勝感激。我是否需要將代碼添加到我的web.configGodaddy發送郵件

System.Net.Mail.MailMessage m = new System.Net.Mail.MailMessage("[email protected]", "To", "subject ", "body "); 
         m.IsBodyHtml = true; 
         SmtpClient smtp = new SmtpClient("relay-hosting.secureserver.net"); 
         smtp.UseDefaultCredentials = true; 
         smtp.Send(m); 

的錯誤信息是這樣的:

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 173.201.192.101:467 Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 173.201.192.101:467

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

+1

什麼似乎是問題? – 2011-12-19 19:46:53

+0

它不發送郵件。我得到一個錯誤屏幕。我是否需要購買godaddy的可信度表格或什麼? – CsharpBeginner 2011-12-19 19:51:50

+0

請編輯您的問題併發布錯誤。 – 2011-12-19 19:53:01

回答

1

我能弄清楚如何做到這一點,它的工作原理。下面的代碼是針對具有相同問題的其他人。

try 
     { 
      using (SmtpClient client = new SmtpClient("smtpout.secureserver.net")) 
      { 
       client.Credentials = new NetworkCredential("godaddyemail", "pw"); 


       //client.Credentials = CredentialCache.DefaultNetworkCredentials; 
       //client.DeliveryMethod = SmtpDeliveryMethod.Network; 

       string to = "send email to who"; 


       System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(); 
       mail.From = new MailAddress("mygodaddyemail", "subject"); 
       mail.To.Add(to); 



       mail.Subject = "New member Alert"; 
       mail.Body = "New member "; 
       mail.IsBodyHtml = true; 

       client.Send(mail); 
       return "sent mail"; 
      } 
     } 
     catch (Exception ex) 
     { 
      // exception handling 
      return ex.ToString(); 
     } 
相關問題