While testing a simple script on a EL9 compatible system, running Rocky Linux 9, I wanted to send a quick e-mail notification at the end of the script.
I have been using the mailx command for at least a decade, and never experienced problems with it. But now this command seems to be gone in Rocky Linux 9 (and other Linux distributions based on EL9).
root@rocky9 ~ # dnf search mailx
Last metadata expiration check: 60 days, 6:03:10 ago on Sat 09 Sep 2023 06:00:58 AM UTC.
No matches found.
There's no mailx package in Rocky Linux 9 anymore?
By searching for mail related packages, the following list is returned:
root@rocky9 ~ # dnf search mail
==================== Name & Summary Matched: mail ====================
ant-javamail.noarch : Optional javamail tasks for ant
asterisk-voicemail.x86_64 : Common Voicemail Modules for Asterisk
asterisk-voicemail-odbc.x86_64 : Store voicemail in a database using ODBC
asterisk-voicemail-plain.x86_64 : Store voicemail on the local filesystem
claws-mail.x86_64 : Email client and news reader based on GTK+
claws-mail-devel.x86_64 : Development package for claws-mail
claws-mail-plugins.x86_64 : Additional plugins for Claws Mail
[...]
s-nail.x86_64 : Environment for sending and receiving mail
smf-spf.x86_64 : Mail filter for Sender Policy Framework verification
spamass-milter.x86_64 : Milter (mail filter) for spamassassin
spamassassin.x86_64 : Spam filter for email which can be invoked from mail delivery agents
spamassassin-iXhash2.noarch : SpamAssassin plugin to lookup e-mail checksums in blacklists
thunderbird.x86_64 : Mozilla Thunderbird mail/newsgroup client
It turns out, that the s-nail package has replaced mailx in EL9. Also the official Rocky Linux 9 documentation mentions the s-nail command to test sending e-mails.
OK then, let's install s-nail.
root@rocky9 ~ # dnf install s-nail
[...]
Installed:
s-nail-14.9.22-6.el9.x86_64
Complete!
Prior to using s-nail, a local MTA (mail server) needs to be installed. Or you run into an error like this:
root@rocky9 ~ # echo "Hello, this is a test mail" | s-nail -s "Test" destination@example.com
s-nail: Cannot start /usr/sbin/sendmail: executable not found (adjust *mta* variable)
/root/dead.letter 8/165
s-nail: ... message not sent
As local MTA I usually chose Postfix.
root@rocky9 ~ # dnf install postfix
[...]
Installed:
postfix-2:3.5.9-19.el9.x86_64
Complete!
Postfix also needs to be started, otherwise you get an error like this:
root@rocky9 ~ # echo "Hello, this is a test mail" | s-nail -s "Test" destination@example.com
postdrop: warning: unable to look up public/pickup: No such file or directory
Alright, Postfix start and then try s-nail again:
root@rocky9 ~ # systemctl restart postfix
With Postfix (or another local MTA) running, let's send some test e-mails.
root@rocky9 ~ # echo "Hello, this is a test mail" | s-nail -s "Test" destination@example.com
No error message this time. What about the mail logs?
root@rocky9 ~ # tail /var/log/maillog
Nov 8 12:08:16 rocky9 postfix/pickup[11032]: B3C3FC1347: uid=0 from=<root>
Nov 8 12:08:16 rocky9 postfix/cleanup[11035]: B3C3FC1347: message-id=<20231108120816.B3C3FC1347@rocky9.localdomain>
Nov 8 12:08:16 rocky9 postfix/qmgr[11033]: B3C3FC1347: from=<root@rocky9.localdomain>, size=346, nrcpt=1 (queue active)
Nov 8 12:08:17 rocky9 postfix/smtp[11037]: B3C3FC1347: to=<destination@example.com>, relay=gmail-smtp-in.l.google.com[108.177.15.26]:25, delay=0.33, delays=0.01/0/0.17/0.15, dsn=5.7.26, status=bounced (host gmail-smtp-in.l.google.com[108.177.15.26] said: 550-5.7.26 This mail has been blocked because the sender is unauthenticated. 550-5.7.26 Gmail requires all senders to authenticate with either SPF or DKIM. 550-5.7.26 550-5.7.26 Authentication results: 550-5.7.26 DKIM = did not pass 550-5.7.26 SPF [rocky9.localdomain] with ip: [xxx.xxx.xxx.xxx] = did not pass 550-5.7.26 550-5.7.26 To mitigate this issue, please visit Gmail's authentication guide 550-5.7.26 for instructions on setting up authentication: 550 5.7.26 https://support.google.com/mail/answer/81126#authentication e3-20020adfe383000000b0031c6d8741b8si3416325wrm.783 - gsmtp (in reply to end of DATA command))
Nov 8 12:08:17 rocky9 postfix/cleanup[11035]: 1059EC1349: message-id=<20231108120817.1059EC1349@rocky9.localdomain>
Nov 8 12:08:17 rocky9 postfix/qmgr[11033]: 1059EC1349: from=<>, size=3595, nrcpt=1 (queue active)
Nov 8 12:08:17 rocky9 postfix/bounce[11039]: B3C3FC1347: sender non-delivery notification: 1059EC1349
Nov 8 12:08:17 rocky9 postfix/qmgr[11033]: B3C3FC1347: removed
Nov 8 12:08:17 rocky9 postfix/local[11040]: 1059EC1349: to=<root@rocky9.localdomain>, relay=local, delay=0, delays=0/0/0/0, dsn=2.0.0, status=sent (delivered to mailbox)
Nov 8 12:08:17 rocky9 postfix/qmgr[11033]: 1059EC1349: removed
The important thing is: The e-mail was sent. Due to Gmail's SPF check of the sender domain (rocky9.localdomain) the mail was not accepted.
But similar to mailx, the from address (sender) can be set in s-nail using the -r parameter:
root@rocky9 ~ # echo "Hello, this is a test mail" | s-nail -s "Test" -r "noreply@senderaddress.example.com" destination@example.com
In this case I used a sender address which matches the SPF record from that sender IP. That worked and the Gmail servers accepted the mail:
Nov 8 12:24:38 rocky9 postfix/smtp[11085]: CD55CC1349: to=<destination@example.com>, relay=gmail-smtp-in.l.google.com[64.233.166.26]:25, delay=0.66, delays=0.02/0.04/0.21/0.39, dsn=2.0.0, status=sent (250 2.0.0 OK 1699446278 f1-20020a5dxxxxxxxxxxxxxxxxxxxxxxxxxb5desi3266616wrw.1082 - gsmtp)
So far it seems that s-nail is a 1:1 replacement of mailx. At least for the most common mail tests.
I mentioned before that we need Postfix (or an alternative) as a local MTA so s-nail can "hand over" the e-mail to a mail system. But s-nail (and mailx) is capable of speaking to a remote MTA, too! By using the -S parameter, additional mail settings, such as SMTP server or SMTP authentication, can be defined on the fly. They can also be placed into a config file located under ~/.mailrc.
root@rocky9 ~ # echo "Hello, this is a test mail" | s-nail -s "Test" -S mta=smtp://relay.example.com:587 -r "noreply@senderaddress.example.com" destination@example.com
This example is the same s-nail command as used before, but uses a remote SMTP server (relay.example.com) as relay host.
No comments yet.
AWS Android Ansible Apache Apple Atlassian BSD Backup Bash Bluecoat CMS Chef Cloud Coding Consul Containers CouchDB DB DNS Database Databases Docker ELK Elasticsearch Filebeat FreeBSD Galera Git GlusterFS Grafana Graphics HAProxy HTML Hacks Hardware Icinga Influx Internet Java KVM Kibana Kodi Kubernetes LVM LXC Linux Logstash Mac Macintosh Mail MariaDB Minio MongoDB Monitoring Multimedia MySQL NFS Nagios Network Nginx OSSEC OTRS Office PGSQL PHP Perl Personal PostgreSQL Postgres PowerDNS Proxmox Proxy Python Rancher Rant Redis Roundcube SSL Samba Seafile Security Shell SmartOS Solaris Surveillance Systemd TLS Tomcat Ubuntu Unix VMWare VMware Varnish Virtualization Windows Wireless Wordpress Wyse ZFS Zoneminder