我正在为我的网站访问者创建一个联系页面,以便向我发送电子邮件(使用C#)。在尝试时,我收到有关EHLO参数的错误。这是我的代码:
我收到了错误:
服务器响应是:语法上无效的EHLO参数。
请帮助
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;
}
提前致谢
答案 0 :(得分:0)
如此处http://forums.asp.net/t/1622198.aspx?Syntactically+invalid+EHLO+argument+s+emailing
所述如果您发送电子邮件时遇到问题,因为语法无效的参数导致EHLO或HELO被拒绝。
1.主机名可能包含下划线(_)。
2.这不是标准做法,为您的域名
3.例如takizo_mail.takizo.com
4.大多数邮件服务器拒绝使用下划线的主机名。
5.Possibility是Windows管理员
答案 1 :(得分:0)
确保服务器名称中只包含拉丁字符,并且没有像下划线等特殊符号。
答案 2 :(得分:0)
MailMessage msg = new MailMessage("from@a.com", "To@y.com");
msg.Subject = "Intraday";
msg.Sender = new MailAddress("sender@y.com");
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);