billypom

nullmailer - send email from the terminal

2025-11-18

Email is neat.

I wanted to utilize my mail server to send emails to myself for various sysadmin purposes. I could not get sendmail or postfix running properly and they are overkill for my use-case. I only needed to send mail.

nullmailer fits, so I sits. The documentation is not great, so I figured I would share how I got it working.

Environment


  • OS: Debian 13

Install


sudo apt install nullmailer

Configuration


nullmailer needs some config files placed in /etc/nullmailer:

  • defaultdomain - the domain that emails are sent from
  • remotes - email login configuration for the remote server

Adjust the following commands based on your needs

echo 'yourdomain.tld' > /etc/nullmailer/defaultdomain
echo 'smtp.gmail.com smtp --auth-login --port=587 --starttls --user=your-name@gmail.com --pass=\"your 2fa token e.g. 1234 abcd 5678 efgh\"' > /etc/nullmailer/remotes
sudo chmod 600 /etc/nullmailer/remotes

Usage


echo "body" | mail -r "sender@yourdomain.tld" -s "subject" "recipient@whateverdomain.tld"

# or 

printf "First line\nNewlines also work" | mail -r "sender@yourdomain.tld" -s "subject" "recipient@whateverdomain.tld"

If you don't receive an email, you can check the mail log at /var/log/mail.log or the various directories in /var/spool/nullmailer to identify any issues.

systemctl status nullmailer.service or journalctl might also help with debugging if you're running systemd.

Happy mailing!

#linux
#email
#server
#mail
#nullmailer
#linux server