SmtpException(语法上是无效EHLO参数) [英] SmtpException (Syntactically invalid EHLO argument)

查看:142
本文介绍了SmtpException(语法上是无效EHLO参数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们只是改变了我们的.NET mailSettings瞄准一个新的SMTP服务器,但我们尝试发送电子邮件时,遇到以下问题语法错误参数或变量服务器响应为:语法上是无效EHLO参数(S)

我认为我们的参数(用户名,主机,密码和端口)是正确的,因为如果我们部署在另外一个服务器相同的应用程序,一切正常。

可以在服务器,我们有问题的名称(计算机名称包含下划线)负责此SMTP例外?如果是这样,应该是解决它的最好方法是什么?

感谢您!

编辑:

我们正在使用基本的.NET System.Net.Mail.SmtpClient如

 客户端=新System.Net.Mail.SmtpClient(主机,Convert.ToInt32(口))
{
    证书=新的NetworkCredential(用户名,密码)
};
Client.Send(消息); / *其中,消息是MailMessage的实例* /
(主机xx.xx.gridserver.com,用户名xx@xxx.com,端口587)
 

解决方案

据<一href="http://social.msdn.microsoft.com/forums/en-US/winforms/thread/7644d037-bb69-41fb-addc-6c23488b6e13"相对=nofollow> 下划线这个环节可能是问题。我们遇到了一模一样的问题,也是一个主机在名称中的下划线。

编辑。

我没有找到一个解决:有人张贴扩展SmtpClient它使用反射来覆盖专用主机变量。 <一href="http://social.msdn.microsoft.com/forums/en-US/netfxnetcom/thread/77f45c5f-76be-400c-a529-a1e49d6d8e62/"相对=nofollow>看到这里的修补程序。

请注意,私人领域的名称已版本的.NET运行库之间的变化,因此修改code如下:

  ///&LT;总结&gt;
///返回专用localHostName字段。
///&LT; /总结&gt;
///&LT;返回&GT;
///的&lt;看到CREF =字段信息/&GT;用于专用
///localHostName字段。
///&LT; /回报&GT;
///&LT;说明&gt;在早期版本的.NET的这个私人领域是localHostName',现在是'clientDomain'&LT; /说明&GT;
私有静态字段信息GetLocalHostNameField()
{
  常量的BindingFlags标志= BindingFlags.Instance | BindingFlags.NonPublic可;
  System.Reflection.FieldInfo结果= typeof运算(SmtpClient).GetField(clientDomain,标​​志);
  如果(空==结果)
    结果= typeof运算(SmtpClient).GetField(localHostName,标志);
  返回结果;
}
 

用法:

  SmtpClientEx客户端=新SmtpClientEx();
client.LocalHostName =localhost的;

MailMessage味精=新MailMessage();
...
msg.Send()
 

We just changed our .net mailSettings to target a new smtp server but we experience the following issue when trying to send e-mail "Syntax error in parameters or arguments. The server response was: Syntactically invalid EHLO argument(s)"

I assume our parameters (userName, host, password and port) are correct as if we deploy the same app in another server, everything is working.

Can the name of the server where we have the issue (Machine Name contains underscore) be responsible for this Smtp Exception? If so, what should be the best way to fix it?

Thank you!

Edit:

We are using basic .net System.Net.Mail.SmtpClient such as

Client = new System.Net.Mail.SmtpClient(host, Convert.ToInt32(port))
{
    Credentials = new NetworkCredential(username, password)
};
Client.Send(message); /*where message is an instance of MailMessage */
(host xx.xx.gridserver.com, userName xx@xxx.com, port 587) 

解决方案

According to this link the underscore could be the problem. We're experiencing exactly the same issue, also on a host with a underscore in the name.

EDIT.

I did find a fix: someone posted an extended SmtpClient which uses reflection to overwrite the private host variable. See here for the fix.

Note that the name of the private field has been changed between version of the .NET runtime, so modify the code as follows:

/// <summary>
/// Returns the private "localHostName" field.
/// </summary>
/// <returns>
/// The <see cref="FieldInfo"/> for the private
/// "localHostName" field.
/// </returns>
/// <remarks>In earlier versions of .NET this private field was 'localHostName', now it is 'clientDomain'</remarks>
private static FieldInfo GetLocalHostNameField()
{
  const BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic;
  System.Reflection.FieldInfo result = typeof(SmtpClient).GetField("clientDomain", flags);
  if (null == result)
    result = typeof(SmtpClient).GetField("localHostName", flags);
  return result;
}

Usage:

SmtpClientEx client = new SmtpClientEx();
client.LocalHostName = "localhost";

MailMessage msg = new MailMessage();
...
msg.Send()

这篇关于SmtpException(语法上是无效EHLO参数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆