
For those of us who roam around the internet, getting a connection here, there and everywhere, trying to find mailservers that are willing to relay outgoing mail for us can be a challenge. While DHCP will give us an IP address, nameservers and a default gateway, there's no traditional model I'm aware of for provising mail relays. Of course, there's a solution to this problem - use your own mail server.
Using your own mail server means that you must configure it to relay mail from lots of possible IP addresses - but only if it's you that's trying to relay. I won't go into the details as to why it's a bad idea to have an open mail relay facing the internet - I'm going to assume you know. Fortunately, it's actually not that difficult to authenticate with your mail server at SMTP time (when you're sending a mail) and ensure that only you, or your valid users, get to use the server.
Step #1: Configure TLS
For this you'll need a server certificate. I've chosen to use CACert as my root signer. You can do the same by signing up for a free account with them - something I'd actively encourage you to do.
/etc/ssl/certs/CACert-class1-root.pem./usr/lib/ssl/misc/CA.pl -newreq-nodes to generate a certificate request for your server. Answer the questions asked, making sure to insert the server's DNS name as the Common Name (eg, YOUR name) section. In my case, it's for one of my mail servers, so I putCommon Name (eg, YOUR name) []:mail.signal2noise.co.uk.newkey.pem (this is your private key. Keep it a secret.) and the other called newreq.pem. (This is the certificate request you need to send to CACert.) I always rename the newkey.pem file to servername-privatekey.pem.newreq.pem file into the text area titled "Paste your CSR below..."servername-publickey.pemcat servername-privatekey.pem servername-publickey.pem > servername-keys.pem
servername-keys.pem file in the /etc/ssl/certs/ directory along with the CACert-class1-root.pem cert from above. We now have all the keys we need. If you have other users on your system, make sure that the servername-key.pem file is not world readable. chmod 0640 servername-key.pem should do the job nicely./etc/postfix/main.cf file:
## TLS
smtp_use_tls = yes
smtpd_use_tls = yes
## Only show AUTH options if TLS is being used.
smtpd_tls_auth_only = yes
## Log the hostname of a remote SMTP server that offers STARTTLS
smtp_tls_note_starttls_offer = yes
## Location of PEM files
smtpd_tls_key_file = /etc/ssl/certs/servername-key.pem
smtpd_tls_cert_file = /etc/ssl/certs/servername-key.pem
smtpd_tls_CAfile = /etc/ssl/certs/CACert-class1-root.pem
smtpd_tls_CApath = /etc/ssl/certs
## Increase this for more verbose logging
smtpd_tls_loglevel = 1
## Add a TLS header
smtpd_tls_received_header = yes
tls_random_source = dev:/dev/urandom
EHLO your.server.name it should now respond with 250-STARTTLS as one of the options.apt-get install libsasl sasl2-bin libsasl2-modulessasl2-bin package will install a file called /etc/default/saslauthd. You will need to edit this file to configure saslauthd to start automatically at boot time.
START=yes
MECHANISMS="pam"
OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd"
Other options can be left at their defaults. The OPTIONS stanza configures the runtime files appear in a location accessible by postfix, running in a chroot jail. Without this, postfix will be unable to communicate with saslauthd.
postfix:saslmkdir -p /var/spool/postfix/var/run/saslauthd
chown -R postfix:sasl /var/spool/postfix/var/run/saslauthdsasldb2 file so that it's accessible by postfix, and configure sasl to be added to the postfix group:adduser postfix sasl
mv /etc/sasldb2 /var/spool/postfix/etc/
ln -s /var/spool/postfix/etc/sasldb2 /etc/sasldb2
chown postfix:sasl /var/spool/postfix/etc/sasldb2/etc/postfix/sasl/smtpd.conf with the following contents:pwcheck_method: saslauthdmain.cf file to allow postfix to use SASL Auth for sending mail:
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain =
broken_sasl_auth_clients = yes
/etc/init.d/saslauthd start/etc/init.d/postfix restart