Relay email (nullmailer): Difference between revisions

From Alpine Linux
mNo edit summary
mNo edit summary
Line 2: Line 2:
== Overview ==
== Overview ==


Nullmailer is lightweight and simple MTA (mail transport agent) which allows to relay local mails to another server. This is useful if you are in example running private server at home and just want to relay notifications from cron etc. to your external mailbox via your ISPs mail server. Nullmailer allow also to rewrite envelope sender which is needed to pass spam checks many ISPs are nowadays doing.
Nullmailer is lightweight and simple MTA (mail transport agent) which allows you to relay local emails to another server. This is useful if you are for in example running a private server at home and just want to relay notifications from cron etc. to your external mailbox via your ISPs mail server. Nullmailer also allowsyou to rewrite the envelope sender which is needed to pass spam checks that many ISPs are nowadays doing.


== Installation ==
== Installation ==


Nullmailer can be found only from the <code>testing</code> branch. [[Repositories#Testing|How to Enable the Testing Repository]]
Nullmailer can be found only in the <code>testing</code> branch. [[Repositories#Testing|How to Enable the Testing Repository]]


{{Cmd|apk add nullmailer@testing}}
{{Cmd|apk add nullmailer@testing}}
Line 13: Line 13:
Nullmailer is configured using individual files under /etc/nullmailer/, one file per setting.
Nullmailer is configured using individual files under /etc/nullmailer/, one file per setting.


When mail is sent to any local user i.e. "root", "logcheck", "me@localhost" etc. then mail can be sent to some external address or addresses (comma separated list) instead:
When mail is sent to any local user e.g. "root", "logcheck", "me@localhost" etc. then the mail can be sent to some external address or addresses (as a comma separated list) instead:


{{Cat|/etc/nullmailer/adminaddr|me@example.com}}
{{Cat|/etc/nullmailer/adminaddr|me@example.com}}


When nullmailer relays mail to remote server then envelope sender can be overridden as often mail gets rejected if envelope sender has non-existent domain like root@localhost.lan (note that envelope sender is not the same as From: header which nevertheless stays root@localhost.lan but that is not typically rejected):
When nullmailer relays mail to remote server then the envelope sender can be overridden because mail is often rejected if the envelope sender contains a non-existent domain like root@localhost.example (note that the envelope sender is not the same as the From: header, which remains root@localhost.example,  but that is not typically rejected):


{{Cat|/etc/nullmailer/allmailfrom|me@example.com}}
{{Cat|/etc/nullmailer/allmailfrom|me@example.com}}


Whenever mail nullmailer deals with addresses without hostname or domain then defaulthost and defaultdomain files can be used to set defaults, but this will do the same using one file. So mail From: me and To: me will become From: me@localhost.example and To: me@localhost.example. Note that this applies to headers which are kind of informational only shown on mail client and envelope sender and recipient must be set correctly in any case using configuration files explained above.
Whenever nullmailer deals with addresses without a hostname or domain then defaulthost and defaultdomain files can be used to set defaults, however this can be also done using one file. So mail From: me and To: me will become From: me@localhost.example and To: me@localhost.example. Note that this applies to headers, which informational only and shown in the mail client. The envelope sender and recipient must still be set correctly using configuration files explained above.


Ideally you would own and control a domain you could use but if not, then set to something guaranteed non-existing domains like localhost.example. Do not just pick some random non-existing domain as somebody could register it in the future:
Ideally you would own and control a domain you could use but if not, then set it to a guaranteed non-existing domain like localhost.example. Do not just pick some random non-existing domain because somebody could register it in the future:


{{Cat|/etc/nullmailer/me|localhost.example}}
{{Cat|/etc/nullmailer/me|localhost.example}}


To configure relay server to which mails are sent to add one line per remote server. Typically this would be your ISPs mail server. Optionally supports different authentication schemes:
To configure the relay server that mails are sent to, add one line per remote server. Typically this would be your ISPs mail server. Optionally, nullmailer supports different authentication schemes:


{{Cat|/etc/nullmailer/remotes|smtp.example.com smtp
{{Cat|/etc/nullmailer/remotes|smtp.example.com smtp
Line 36: Line 36:
== Logging ==
== Logging ==


Nullmailer only logs to stdout and stderr which means syslog cannot be used trivially. Instead it possible to make OpenRC write stdout and stderr to log files:  
Nullmailer only logs to stdout and stderr which means syslog cannot be used trivially. Instead, it is possible to make OpenRC write stdout and stderr to log files:  


{{Cat|/etc/conf.d/nullmailer|<nowiki>output_log="/var/log/mail.log"</nowiki>
{{Cat|/etc/conf.d/nullmailer|<nowiki>output_log="/var/log/mail.log"</nowiki>
<nowiki>error_log="/var/log/mail.err"</nowiki>}}
<nowiki>error_log="/var/log/mail.err"</nowiki>}}


As nullmailer runs as user of the same name, it cannot create logfiles by itself. Just create log files manually instead:
As nullmailer runs as a user of the same name, it cannot create log files by itself. Just create the log files manually instead:


{{Cmd|touch /var/log/mail.log /var/log/mail.err
{{Cmd|touch /var/log/mail.log /var/log/mail.err
Line 49: Line 49:


== Testing ==
== Testing ==
To test configuration just send out few test mails to root, to some existing address etc:  
To test configuration just send out few test emails to root and to some existing address, etc.:  


{{Cmd|<nowiki>echo -e "Subject: Nullmailer testing\n\nSending to root." | sendmail root</nowiki>
{{Cmd|<nowiki>echo -e "Subject: Nullmailer testing\n\nSending to root." | sendmail root</nowiki>
<nowiki>echo -e "Subject: Nullmailer testing\n\nSending to me." | sendmail me@example.com</nowiki>
<nowiki>echo -e "Subject: Nullmailer testing\n\nSending to me." | sendmail me@example.com</nowiki>
}}
}}

Revision as of 14:48, 1 February 2025

Overview

Nullmailer is lightweight and simple MTA (mail transport agent) which allows you to relay local emails to another server. This is useful if you are for in example running a private server at home and just want to relay notifications from cron etc. to your external mailbox via your ISPs mail server. Nullmailer also allowsyou to rewrite the envelope sender which is needed to pass spam checks that many ISPs are nowadays doing.

Installation

Nullmailer can be found only in the testing branch. How to Enable the Testing Repository

apk add nullmailer@testing

Configuration

Nullmailer is configured using individual files under /etc/nullmailer/, one file per setting.

When mail is sent to any local user e.g. "root", "logcheck", "me@localhost" etc. then the mail can be sent to some external address or addresses (as a comma separated list) instead:

Contents of /etc/nullmailer/adminaddr

me@example.com

When nullmailer relays mail to remote server then the envelope sender can be overridden because mail is often rejected if the envelope sender contains a non-existent domain like root@localhost.example (note that the envelope sender is not the same as the From: header, which remains root@localhost.example, but that is not typically rejected):

Contents of /etc/nullmailer/allmailfrom

me@example.com

Whenever nullmailer deals with addresses without a hostname or domain then defaulthost and defaultdomain files can be used to set defaults, however this can be also done using one file. So mail From: me and To: me will become From: me@localhost.example and To: me@localhost.example. Note that this applies to headers, which informational only and shown in the mail client. The envelope sender and recipient must still be set correctly using configuration files explained above.

Ideally you would own and control a domain you could use but if not, then set it to a guaranteed non-existing domain like localhost.example. Do not just pick some random non-existing domain because somebody could register it in the future:

Contents of /etc/nullmailer/me

localhost.example

To configure the relay server that mails are sent to, add one line per remote server. Typically this would be your ISPs mail server. Optionally, nullmailer supports different authentication schemes:

Contents of /etc/nullmailer/remotes

smtp.example.com smtp smtpa.example.com smtp --port=2525 --user=user --pass=pass smtpa.example.com smtp --port=2525 --auth-login --user=user --pass=pass

Logging

Nullmailer only logs to stdout and stderr which means syslog cannot be used trivially. Instead, it is possible to make OpenRC write stdout and stderr to log files:

Contents of /etc/conf.d/nullmailer

output_log="/var/log/mail.log" error_log="/var/log/mail.err"

As nullmailer runs as a user of the same name, it cannot create log files by itself. Just create the log files manually instead:

touch /var/log/mail.log /var/log/mail.err chown nullmailer:adm /var/log/mail.log /var/log/mail.err chmod 0640 /var/log/mail.log /var/log/mail.err

Testing

To test configuration just send out few test emails to root and to some existing address, etc.:

echo -e "Subject: Nullmailer testing\n\nSending to root." | sendmail root echo -e "Subject: Nullmailer testing\n\nSending to me." | sendmail me@example.com