2014-06-11 155 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);