2014-06-11 157 views
0

我正在爲我的網站的訪問者發送電子郵件(在C#中)的聯繫頁面。嘗試時,我收到有關EHLO參數的錯誤。這裏是我的代碼:發送電子郵件在ASP.NET C#

我得到了錯誤:

The server response was: Syntactically invalid EHLO argument(s).

請幫助

try 
    { 
     MailMessage _email = new MailMessage(); 
     String MessageString = ""; 
     MessageString = "<br>"; 
     MessageString += "<b>Message from " + champNom.Value + "</b><br /><br />"; 
     MessageString += "<br/><br/>"; 
     MessageString += champMail.Text; 
     _email.Subject = "Mail from " + champNom.Value + " (Email adress: " + champEmail.Text + ")"; 
     _email.From = new System.Net.Mail.MailAddress(System.Configuration.ConfigurationManager.AppSettings["SenderForEmail"].ToString(), "MyName"); 
     _email.To.Add(new System.Net.Mail.MailAddress(System.Configuration.ConfigurationManager.AppSettings["AdminForEmail"].ToString(), "MyName")); 
     if (chkCCMyself.Checked) { 
      _email.CC.Add(new System.Net.Mail.MailAddress(champEmail.Text, champNom.Value)); 
     } 
     _email.Body = MessageString; 
     _email.IsBodyHtml = true; 
     System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(); 
     smtp.EnableSsl = false; 
     //smtp.UseDefaultCredentials = true; 
     //smtp.DeliveryMethod = SmtpDeliveryMethod.Network; 
     smtp.Host = System.Configuration.ConfigurationManager.AppSettings["HostForEmail"].ToString(); 
     smtp.Port = 587; 
     smtp.Credentials = new System.Net.NetworkCredential(System.Configuration.ConfigurationManager.AppSettings["SenderForEmail"].ToString(), System.Configuration.ConfigurationManager.AppSettings["SenderPswdForEmail"].ToString()); 
     smtp.Send(_email); 
     Page.RegisterStartupScript("UserMsg", "<script>alert('Mail envoyé avec succès...');if(alert){ window.location='contact.aspx';}</script>"); 
    }catch(Exception err){ 
     champMail.Text += Environment.NewLine + err.Message; 
    } 

在此先感謝

+2

可能相關:HTTP:// stackoverflow.com/questions/3730123/smtpexception-syntactically-invalid-ehlo-argument – DaveParsons

回答

0

由於這裏記錄http://forums.asp.net/t/1622198.aspx?Syntactically+invalid+EHLO+argument+s+emailing

如果電子郵件having由於語法無效的參數導致被拒絕的EHLO或HELO問題。

1.可能的主機名包含下劃線(_)。

2,本是不標準的做法,有_爲您的域名

3.對於例如takizo_mail.takizo.com

4.Most有下劃線的郵件服務器拒絕主機名。

5.Possibility是Windows管理員

+4

5個可能原因的好名單難點1至4都意味着相同。 ;) –

+1

非常感謝;但是我的主機名沒有下劃線 – cayal

+0

恩,謝謝大家。重點是我的筆記本電腦名稱是myName_pc:我剛剛重命名它,它工作。 – cayal

0

確保服務器名稱中只有拉丁字符,就像沒有下劃線的特殊符號等

+0

謝謝,但我的主機名或服務器名稱中沒有下劃線 – cayal

0
 MailMessage msg = new MailMessage("[email protected]", "[email protected]"); 
     msg.Subject = "Intraday"; 
     msg.Sender = new MailAddress("[email protected]"); 
     msg.IsBodyHtml = false; //to preserve line breaks and to avoid the need for <br>s 
     msg.Body = "Body"; 
     SmtpClient client = new SmtpClient("Server"); 
     client.Send(msg);