.NET SMTP mail - error = helo command rejected need fully-qualified hostname

16,798

Solution 1

Change the hostname from an IP address to its name, e.g. "smtp.provider.com" or if its internal "mailserver.domain".

UPDATE:

Try read this system.net.mail.smtpclient fqdn required and this the FQDN is not sent when you send a HELO or EHLO.

Solution 2

Create a user with password on your SMTP server then apply the following settings:

        smtp.UseDefaultCredentials = false;
        smtp.Credentials = new NetworkCredential("user", "pass");
        smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
        smtp.Port = 25;
        smtp.EnableSsl = true; // or false depending your server
Share:
16,798
richard
Author by

richard

I love this site. I am here to learn, and try to contribute back as much as possible. As an aside, I can't thank everyone on this site enough for their answers. This site (and it's sister sites through SE) are INVALUABLE.

Updated on June 05, 2022

Comments

  • richard
    richard about 2 years

    I am trying to send email in a .NET console application. I have an SMTP server with i.P. address X.X.X.X (sanitized to protect the innocent).

    The SMTP server has been set up (the relay configured) to allow email from the server that is hosting the .NET console app, and send that email to the outside world.

    I have tested this with telnet from the server hosting the console app. I successfully sent an email with telnet console from the server hosting the console app using the SMTP server's I.P. address. There is no authentication required when using telnet. I have not been given any connection credentials.

    But when I try to do it in the .NET app, I get the following error:

    Syntaz error, command unrecognized. The server response was: : Helo command rejected: need fully-qualified hostname

    Here is my code:

    string mailMessagetest = "test";
            string subjecttest = "test";
            List<string> recipienttest = new List<string>();
            recipienttest.Add("[email protected]");
    
            utility.SendMail(recipienttest, subjecttest, mailMessagetest);
    

    Here is the function SendMail:

            public static void SendMail(List<string> recipient, string subject, string message)
        {
            MailMessage mailMessage = new MailMessage();
            mailMessage.From = new MailAddress("[email protected]");
    
            foreach (string to in recipient)
            {
                mailMessage.To.Add(to);
            }
    
            mailMessage.Subject = subject;
            mailMessage.Body = message;
    
            SmtpClient client = new SmtpClient();
            client.Host = "X.X.X.X";
            client.Port = 25;
            client.Send(mailMessage);
        }