Sending email from a dynamic IP address

If you want to run a mail server on your Debian server at home then you are probably on a dynamic IP address (one that changes once a day) from your internet provider. The problem with dynamic IP addresses is that they are blacklisted by most mail servers on the internet. You cannot send email directly to other mail servers and need to send your email through a server that is not blacklisted. In this case you just need two things:

  • You need to send out emails through your ISPs mail relay. If they don't offer such a service you can still try to find a commercial SMTP relay elsewhere on the internet.
  • Your ISP must not block SMTP (TCP port 25) connections to your IP address. If they do you cannot be sent emails from other mail servers.

Without these prerequisites I suggest you get an inexpensive VPS (virtual private server) and run the mail server from there.

Sending out email through your ISP is not that hard. Your ISP very likely offers an SMTP server that you can use with a username and a password. If you use their SMTP server from your mail client or from your mail server is technically no difference. So if you can send emails from your mail client then you are set. In your /etc/postfix/main.cf you will have to set:

smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
relayhost = [name.of.your.isp.relay.server]

(In case you wonder: configuration statements like smtp_* stand for outgoing SMTP while smtpd_* statements are for incoming SMTP connections. So these settings apply to outgoing SMTP connections.)

This sets "name.of.your.isp.relay.server" as the hostname of your ISP's relay server. Of course you need to set the right name here. The brackets means that no DNS lookup for MX records is done. The "relayhost" is the name of the server that Postfix will send all outgoing emails to. Without a "relayhost" Postfix would use DNS lookups to determine which mail server is responsible for a certain domain. The sasl_passwd file is where the username and password will be set that you have to use for authenticating at your ISP's relay server. The file looks like this.

[name.of.your.isp.relay.server]     herbert.ludkins:Ialenuv2

Pretty easy. You name the relay server exactly as in "relayhost", insert a space and then write the username, a colon and the password. Afterwords you need to compile this file as you want to use is as a "hash":

postmap /etc/postfix/sasl_passwd

This will give you an sasl_passwd.db file that Postfix can use.

You can also read about these settings in the Postfix documentation on SMTP authentication.