[MAILX ERROR: STATUS=BOUNCED] Fixing Mailx error when sending emails from Command line

Mailx troubleshooting

Mailx is an intelligent mail processing system, which has a command syntax reminiscent of ed(1) with lines replaced by messages. It is based on Berkeley Mail 8.1, is intended to provide the functionality of the POSIX mailx command, and offers extensions for MIME, IMAP, POP3, SMTP, and S/MIME. Mailx provides enhanced features for interactive use, such as caching and disconnected operation for IMAP, message threading, scoring, and filtering. It is also usable as a mail batch language, both for sending and receiving mail. While trying to send an email from CLI on a local server to an external email address, you can come across the error log below.

echo -e "testing email via from command line\n\nsent on: $(date)" | mailx -r "Test-Email <>" -s "test cli email $(date)" --
Email sending issues

Fixing Mailx error when sending emails

To fix this, make sure you have the SMTP server address (either Gmail or your ISP) and also authentication to log in (Some ISP’s allow anonymous) then use the command below

echo "This is a test email on CLI initiated using mailx" | mailx -vvv -s "Test mail" -r "" -S smtp="your smtp server address"
Command line email errors

– Establish a certificate directory for secure storage. Include new certificates and keys – a step toward fixing Mailx error when sending emails.

mkdir ~/.certs
certutil -N -d ~/.certs

Download the certificate from Gmail and import the cert file into the new database.

echo -n | openssl s_client -connect | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/gmail.crt
certutil -A -n "Google Internet Authority" -t "C,," -d ~/.certs -i ~/.certs/gmail.crt

Add configurations into the mailx config file (/etc/mail.rc)

account gmail {
set smtp-use-starttls
set ssl-verify=ignore
set smtp-auth=login
set smtp=smtp://
set from=""
set smtp-auth-password=jjdeuen@SGY^
set ssl-verify=ignore
set nss-config-dir=/home/path/to/.certs

Test Email.

echo -e " body " | mailx -A gmail -s "Subject"

I hope you found this blog post on Fixing Mailx error when sending emails helpful. If you have any questions, please let me know in the comment session.

Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x