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 E开发者_开发问答HLO 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)
EHLO
is only optionally supported by mailservers. If the server starts with EHLO
, then the client can use EHLO
(and implied further functionality). If the server starts with HELO
it's more basic, and the client can't say EHLO
back without getting either (a) an error + failure or (b) an error + ability to fallback on HELO
(so you could get the error, but still send mail).
Check the software running on the new server, perhaps upgrade it or switch it to the software running on the old server (if that's possible) or there's probably a setting somewhere to stop mailSettings from using the advanced greeting.
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()
Try removing underscore and not latin letters from the name of the computer
Example :
I have "PC-4-ПК" and after change to "PC-4" everething works fine.
精彩评论