[英]Send email in ASP.NET C#
I'm creating a contact page for visitors of my web site to send me email (in C#). 我正在为我的网站的访问者创建一个联系页面,以向我发送电子邮件(使用C#)。 When trying, I got an error about EHLO argument(s).
尝试时,出现关于EHLO参数的错误。 Here is my code:
这是我的代码:
I got the error: 我得到了错误:
The server response was: Syntactically invalid EHLO argument(s).
服务器响应为:语法上无效的EHLO参数。
Please, help 请帮忙
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;
}
Thanks in advance 提前致谢
As documented here http://forums.asp.net/t/1622198.aspx?Syntactically+invalid+EHLO+argument+s+emailing 如此处所述http://forums.asp.net/t/1622198.aspx?语法上+无效+ EHLO + argument + s + emailing
If you email having problem with rejected EHLO or HELO, caused by syntactically invalid argument(s). 如果通过电子邮件发送因语法无效的参数而导致的EHLO或HELO拒绝问题。
1.Possible the hostname contains underscore(_). 1.可能的主机名包含下划线(_)。
2.This is not standard practice, having _ for your domain 2.这不是标准做法,您的网域使用_
3.for example takizo_mail.takizo.com 3.例如takizo_mail.takizo.com
4.Most of the mail server rejected hostname with underscore. 4.大多数邮件服务器拒绝带下划线的主机名。
5.Possibility is a Windows Admin 5.Possibility是Windows管理员
确保服务器名称中仅包含拉丁字符,并且不包含下划线等特殊符号。
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.