Sending emails from the command line - sendemail

Hello,

On CentOS7, I can easily send emails using the following syntax:

sendemail -f [sender] -t [recipient] -u ‘Email Subject’ -m ‘$(cat body.txt)’ -s [SMTP server] -o tls=no -xu [SMTP user] -xp [SMTP user password]

However, on RockyLinux 9, it returns the following error:

Dec 05 18:08:15 sendemail[4576]: ERROR => Received: 500 5.5.2 bad chars in command

Dec 05 18:08:15 sendemail[4576]: NOTICE => EHLO command failed, attempting HELO instead

Dec 05 18:08:15 sendemail[4576]: ERROR => Received: 500 5.5.2 bad chars in command

and I cannot understand what the problem is.

This is just a guess, because there is not enough detail in the above, but because the first error appears to be “EHLO command failed, attempting HELO instead”, I have to ask if the HOSTNAME contains any invalid characters (such as an underscore) which is NOT allowed per RFC 1123 (and RFC 952) which ONLY allows these characters:

Letters (a-z, A-Z)

Numbers (0-9)

Hyphens (-)

Periods (.) to separate parts.

Hope this might help,

Tony

I tried to simplify, but the problem remains

immagine

The domain, username, and password don’t have any strange characters.

Please note that I was asking about the HOSTNAME, not the domain.

I asked Google Gemini for its additional thoughts, and here is the summary:

Summary Checklist

  1. Check the Hostname: Run hostname. If it doesn’t have a dot in it (like my-server.local), the SMTP server will likely reject it.

  2. Add the FQDN flag: Add -o fqdn=localhost or -o fqdn=yourdomain.com to the command.

  3. Check for “Dead” Software: sendemail (the script) is effectively “abandonware.” On Rocky Linux 9, it is highly recommended to use s-nail or postfix (sendmail compatible binary) which are actively maintained and handle modern security protocols much better.

Perhaps use the equivalent s-nail command as a more modern alternative.

Hope this might help,

Tony

The hostname was empty.

I tried setting the hostname to ‘rockyserver.localdomain’ but it still doesn’t work.

I found a solution with a script using msmtp, and in the .msmtprc file I enter the data for accessing the SMTP server.

Thanks for your help.

Do you have the perl-Sys-Hostname rpm installed? It is located in the EPEL repo.

I don’t recall if this is the same problem, but I also had a problem with getting sendemail working on EL9 systems and installing perl-Sys-Hostname got it working.

EL8 properly identifies perl-Sys-Hostname as a dependency of sendemail. EL9 doesn’t have it as a dependency even though it needs it.

Oh and EPEL doesn’t have sendemail for EL10 - apparently the upstream is dead.

https://bugzilla.redhat.com/show_bug.cgi?id=2390899

A kind fellow pointed me to swaks as a replacement for sendemail.

https://linux.die.net/man/1/swaks

Here are some execution examples:

swaks \
        --from < from@email.com > \
        --to < to@email.com > \
        --server < mail.server.com > \
        --port 25 \
        --tls \
        --header 'Subject: Test email using swaks with attachment' \
        --body "This is a test email using swaks with an attachment." \
        --attach @/root/test_file.txt

swaks \
        --from < from@email.com > \
        --to < to@email.com > \
        --server < mail.server.com > \
        --port 25 \
        --tls \
        --header 'Subject: Test email using swaks with attachment and body file' \
        --body @/root/body_file.txt \
        --attach @/root/test_file.txt

swaks \
        --from < from@email.com > \
        --to < to@email.com > \
        --server < mail.server.com > \
        --port 25 \
        --tls \
        --header 'Subject: Test email using swaks with 3 attachments and body file' \
        --body @/root/body_file.txt \
        --attach @/root/test_file.txt \
        --attach @/root/test_file1.txt \
        --attach @/root/test_file2.txt