Sometimes all you want to do is to allow your server to send emails. Postfix, exim and sendmail can all be configured to do this but they are complex to configure and relatively heavy-weight just to be used as a simple outgoing message transfer agent (MTA). This is where nullmailer comes in handy.
Nullmailer is a tiny MTA that is a drop in replacement for the more complex mailers mentioned above. All that it does is accept outgoing mails and forward them via your normal SMTP mail relay server. The examples in this article are based on Debian Linux but should be helpful with other distros as well.
It’s easy to install:
sudo apt-get install nullmailer
Any other mail transfer agent you have installed will be removed as part of the install process.
Once installed you can modify the configuration files in /etc/nullmailer.
This is where you configure the remote mail relay server that your outgoing emails are forwarded through:
<your relay mailserver> smtp --starttls --insecure --port=<portno> --user=<username> --pass=<password>
If you have control over the relay server then I find it easier to leave off the –user and –pass options and instead whitelist the sender IP address.
This is where you configure how your server will identify itself when connecting to the remote relay host. This is used when connecting to the remote relay server and literally controls the name used in the SMTP HELO command:
Will connect to the remote relay server using:
It’s best to use the fully qualified domain name of the server here, as defined in DNS. Ideally also add a PTR (reverse lookup) record that resolves to the same.
And that’s all! Just a little bit easier than postfix, sendmail or exim!
There are other configuration options as well, but I’ve never found them necessary. There is a link to more information about that at the end of this article.
You can send a simple test email from the command prompt using the following:
mail -s "Some subject" -a "From: <your from email address>" <your to email address>
so as an example
mail -s "Some subject" -a "From: <[email protected]>" <[email protected]>
You will then be prompted to enter a Cc: address (use ENTER to leave blank) and the email content (use CTRL+D to finish). Hopefully if you have everything set up correctly, the email will arrive in your inbox. It’s a good idea to also test using an external recipient mailbox located on another server just to ensure that the emails are being relayed correctly.
All mails sent through nullmailer are processed into the mail queue directory. On Debian this is in /etc/spool/nullmailer/queue.
There is no timeout on sending mails, so if there is a problem with delivery it will keep retrying forever. The simple solution to this is a daily cron job such as below which will delete all emails in the queue older than 24 hours:
find /var/spool/nullmailer/queue -mindepth 1 -mtime +1 -delete
You could also modify this to just copy the mails somewhere else for your perusal. In my experience it’s not necessary though as it’s only occasional system alerts using email address such as [email protected] that get stuck.
There are some great articles on using nullmailer that go into a lot more technical detail at http://troubleshooters.com/linux/nullmailer/#_Configuring_Nullmailer
Found This Useful?
If you have found this useful, why not help to support the site and buy me a coffee or perhaps a cheeky beer? Thanks!
Websites Built For You