Local mail on Linux workstations can still work very much like 20+ years ago on Unix. Every user has a mailbox under
/var/spool/mail/. Some local services can produce administrative mails, namely cron jobs and security mails from sudo.
However, computing has changed a lot in the last 20 years. Most Linux workstations have only one (human) user. Often she or he is also the administrator (root). The user might also have several machines, at home, at work, a lightweight for travelling, a workhorse for software development. Many of these machines have no valid DNS name or it might change while travelling. And many users don’t want to and would never remember to check local mailboxes, whether there could be any output from a failed cron job. However, everybody should have a mail account somewhere in the “cloud” or at their ISP (unless they run their own mailserver). So the easiest would be just to have all local mail delivered to that single mailbox somewhere on the net.
In Ubuntu installations there is often no mailer (MTA) installed at all. In the past I have used ssmtp to get mail to the local root user delivered to the net. Unfortunately it does not work for mail from “normal” users (uid ≥ 1000). Also the program does not look like it’s actively maintained. So that might be a dead-end solution.
In OpenSUSE you always have postfix installed. I have tried uninstalling it in the past because it’s a massive overkill if your daily mails are handled somewhere else. However, the dependencies were too complicated so I have given up on that approach. And it might be useful to know if some daemon produces mail. So I have configured postfix to send all mail to my “normal” mailbox on the net.
First, having a mail server running on the internet might be dangerous, if you don’t know what you are doing and don’t spend enough time and effort to maintain and monitor it. Luckily in the default configuration in OpenSUSE makes postfix to listen on the loopback network interface only, so I don’t think you need to worried too much that it will be misused in some spam sending operations.
Unless the mail provider you are using accepts mail from senders without a valid DNS name (mine doesn’t), the first thing you need to do is to make sure that your mail gets a valid sender addresses. In postfix you do this by adding the desired mappings to the file
Here I assumed that
- only users root and jdoe will ever send mail. I you have other senders, add respective lines
- the mail account firstname.lastname@example.org supports tags separated by a plus sign (e.g. gmail does that). This way you can easily see where some mail originated from. (Without the tags you still dig out all the information from the mail headers)
Next you have to make sure that mails sent to local accounts end up in your desired mail account. Analogously to the above a file
/etc/postfix/recipient_canonical can be used. However, at least the default postfix configuration in OpenSUSE does not use such a file. So you need to do 3 steps
- Create the file
Again I assumed that only 1 user and root will ever receive local mail. However, the postfix configuration already comes with list a of aliases (like postmaster and abuse) which are mapped to root. So I’d assume mail to those would also be forwarded, although I haven’t seen the need to test it.
- Because this file is not previously configured in postfix you need to do so by adding the following lines to
recipient_canonical_classes = envelope_recipient, header_recipient
recipient_canonical_maps = hash:/etc/postfix/recipient_canonical
- Postfix requires the text file
/etc/postfix/recipient_canonicalto be converted into binary before usage. This can be done using the
postmapcommand. However, OpenSUSE converts all known files automatically when the postfix service is (re)started. So it’s enough to add the
name recipient_canonicalinto the
POSTFIX_MAP_LISTin the file
Here consumer grade Internet connections are not able to use port 25 freely in order to prevent private PCs being used as spam distributors. Outgoing traffic to that port is limited to the MTA of your own ISP. A final step is still needed to make the forwarding of mail work. Set the nexthop in
Of course this might be very different depending on country and ISP.
Finally restart the postfix service
sudo systemctl restart postfix
For testing send yourself a mail
$ mail -s "test mail" root
This mail was sent to root, but should end up in my "normal" mailbox
To read the logs you can use
$ sudo journalctl -b -u postfix
- TLS encryption
- Authentication at SMTP server