Debian, minimum to send mail but not receive any

From Andreida
Revision as of 02:54, 2 December 2022 by Andreas (talk | contribs)

sSMTP

After not being able to set the 'from' for mail from nullmailer, I tried sSMTP. Getting mails from 'root' is not really working if you have multiple server which send you mails.

  • install
apt-get install ssmtp
  • config in /etc/ssmtp/
    • ssmtp.conf
      • root=external-mail-address
      • mailhub=MAILSERVER-YOU-USE
      • #rewriteDomain=YOUR-DOMAIN.com (not so sure about this, I left it commented = disabled)
      • #hostname=<hostname> (should already be set, I disabled it for now)
  • revaliases
    • root:externalMailAddress:SMTP-Server


Set mailhub and you are good to go.

echo 'This is a test!' | mail -s 'This is a subject' You@YourExternalMail.org

Now the correct 'full name' from /etc/passwd will be used. If you are getting mail from root, that is normal if you did not change that before :-)

chfn -f 'root (Miracle Wiki Server)' root

Now you get mails from 'root (Miracle Wiki Server)' or 'root (backup-server)' which just makes so much more sense.

sending to root

echo test1 | mail -s test1 root

always gave me a relay error. I found out it takes the first entry after the external ip from /etc/hosts, adds it to root and uses that construct as new 'to'. Meaning I tried to send mail to 'root@backup' or 'root@backup.domain.de' depending on the sequence of the entries in the /etc/hosts file. I tried to use 'localhost' as first entry for the external ip which means it now looks like (x.x.x.x is an external ip like 123.22.33.56):

127.0.0.1 localhost localhost.localdomain
x.x.x.x localhost host.domain.com host

This is probably VERY wrong, but it works. Now I can send mails to root and it tries to send to root@localhost and then /etc/ssmpt/revaliases is used and it then uses the correct target mail address. NO idea why that does not work for root@domain.com if it is in revaliases.


nullmailer

(source)

  • install
apt-get install nullmailer mailutils
  • Fully qualified domain name: yourCurrentServer (does NOT to have be fully qualified)
  • SMTP server: imap.yourdomain.com

It should work now, but you can tweak inside /etc/nullmailer/ the following files:

  • inside /etc/nullmailer
    • adminaddr - target mail (not understood yet by me, sorry; I think this should contain your normal external target email too. But I am guessing here!)
    • defaultdomain - source mail (so the sender not root@server but root@server.domain.com)
    • remotes - target login

from debian.org:

adminaddr If this file is not empty, all recipients to users at either "localhost" (the literal string) or the canonical host name (from /etc/mailname) are remapped to this address. This is provided to allow local daemons to be able to send email to "somebody@localhost" and have it go somewhere sensible instead of being bounced by your relay host. To send to multiple addresses, put them all on one line separated by a comma.

So far this works for mails to root@localhost. But as soon as the target is just "root", then it does not work any more. :-(

Good:

The original intend of this program has been reached, I can send to my external mail address without problems.
Example:

echo 'This is a test!' | mail -s 'This is a subject' You@YourExternalMail.org

Not good:

  • mails to root (without @localhost) are not being send
  • outgoing mails have as sender 'root', no idea where to change this to give it a meaningful (server related) name