Postfix setup on a laptop.
older article that I’ve revived.
Problem⌗
The problem: you have a laptop and you’re not always connected to the Internet. Still you want to sent mail even when you’re offline. You cannot use just any mail server out there, ‘cause a lot of them don’t relay. So you must use your own mail server.
You'll need:
- postfix, only used for queuing and forwarding the mail
- openSSH, for setting up a tunnel
OpenSSH config You will need to create a ssh tunnel to your mail server. This is the command I use:
ssh -2 -N -f -L 10025:elektron.atoom.net:25 miekg@elektron.atoom.net 2>/dev/null
Of course you also want to setup ssh so that you can login without typing a password.
postfix config Next you must tell postfix to use you’re tunnel. It is also important to keep postfix from doing MX lookups. In the main.cf of postfix add the following:
relayhost = [127.0.0.1]:10025 # use the tunnel, no MX lookups
defer_transports = smtp # only send when online
mydestination = localhost.localdomain # not sure if this is needed
system config
Put the startup commands in /etc/dhclient-exit-hooks
. This way every time
you get a IP number from a dhcp-server the tunnel is re-established and the mail is
flushed, /etc/dhclient-exit-hooks
:
# start an ssh tunnel to elektron
ssh -2 -N -f -L 10025:elektron.atoom.net:25 miekg@elektron.atoom.net 2>/dev/null
# run the mailqueue
/usr/sbin/sendmail -q
Also make a cronjob that runs every now and then to flush the queue:
# run queue every 5 minutes
*/5 * * * * root test -x /usr/sbin/sendmail && \
nice -n10 /usr/sbin/sendmail -q
That’s it. Mail should now be queued until it can be delivered via you’re own mail server.