2011-12-19 110 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(); 
     }