notes:postfix-stunnel-smtps
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionLast revisionBoth sides next revision | ||
notes:postfix-stunnel-smtps [2014/11/22 18:12] – created admin | notes:postfix-stunnel-smtps [2014/11/25 11:40] – [Stunnel configuration] admin | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Relaying mail with Postfix and Stunnel through | + | ====== Relaying mail with Postfix and Stunnel through SMTPS with Debian 7====== |
- | + | ||
- | The Postfix SMTP client does not support the obsolete " | + | |
- | + | ||
- | 514 sudo apt-get install libsasl2-modules | + | |
- | + | ||
- | alled your own virtual server running Postfix. Now you want to send mail from it to the outside world. You don't want the work of running a full-blown mail server. | + | |
- | + | ||
- | Problem is, all mail services aren't equal. Ones like Gmail are sophisticated and support the more recent TLS protocol. Many shared and budget hosting services don't. They use an older SSL protocol, and Postfix isn't designed to handle it. The solution is to create your own local SSL tunnel between Postfix and the relay server. | + | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | With the smtp_sasl_password_maps parameter, we configure the Postfix SMTP client to send username and password information to the mail gateway server. As discussed in the next section, the Postfix SMTP client supports multiple ISP accounts. For this reason the username and password are stored in a table that contains one username/ | + | |
- | + | ||
- | / | + | |
- | # destination | + | |
- | [mail.isp.example] | + | |
- | # Alternative form: | + | |
- | # [mail.isp.example]: | + | |
- | + | ||
- | Important | + | |
- | + | ||
- | Keep the SASL client password file in / | + | |
- | + | ||
- | Use the postmap command whenever you change the / | + | |
- | + | ||
- | If you specify the " | + | |
- | + | ||
- | If you specify a non-default TCP Port (such as ": | + | |
- | + | ||
- | + | ||
- | In this example, I’m using the Comcast SMTP server as my smarthost — replace smtp.comcast.net: | + | |
- | + | ||
- | Install stunnel and Postfix with sudo apt-get install stunnel mailutils postfix | + | |
- | If you weren’t automatically prompted to configure Postfix, run sudo dpkg-reconfigure postfix to access the configuration wizard. Configure Postfix as a “Satellite system”. You must enter a valid domain name for “System mail name”, so use example.com. For “SMTP relay host”, enter [127.0.0.1]: | + | |
+ | Do you have setup your own Debian 7 VPS and you want to send mail from it to the outside world without running a full-blown mail server? You can install Postfix and use it in satellite mode, relaying email to another mail server. | ||
+ | However, all mail services aren't equal. Ones like Gmail are sophisticated and support the more recent TLS protocol, while many shared and budget hosting services don't. The latter often use an older SSL protocol, and Postfix SMTP client does not support the obsolete " | ||
===== Stunnel configuration ===== | ===== Stunnel configuration ===== | ||
- | Install stunnel in Ubuntu or Debian with... | + | Install stunnel in Ubuntu or Debian with |
- | + | apt-get install stunnel | |
- | sudo apt-get install stunnel | + | Enable it on startup by editing / |
+ | # | ||
+ | ENABLED=1 | ||
- | Enable it on startup by editing | + | Create a .conf file in etc/stunnel directory with |
+ | vim /etc/stunnel/stunnel.conf | ||
+ | and paste the following text inside | ||
- | #ENABLED=0 | + | client |
- | ENABLED=1 | + | |
+ | |||
+ | [smtp-tls-wrapper] | ||
+ | accept = 11125 | ||
+ | connect = srv-hp12.netsons.net: | ||
- | Create a .conf file in etc/stunnel directory. I named this one / | + | In this case, 11125 is our local port (but could be different) and will be user by Postfix to connect to stunnel. The connect line has the fully qualified domain name (srv-hp12.netsons.net) |
- | [smtp-tls-wrapper] | + | Now start stunnel with |
- | accept = 11125 | + | |
- | client = yes | + | |
- | connect: MY_SMTP_HOSTNAME: | + | |
+ | and test your SMTPS tunnel with | ||
+ | telnet localhost 11125 | ||
+ | | ||
+ | If everything is working, you should see the greeting line from your smarthost, something like | ||
+ | Trying ::1... | ||
+ | Trying 127.0.0.1... | ||
+ | Connected to localhost. | ||
+ | Escape character is ' | ||
+ | 220-srv-hp12.netsons.net ESMTP Exim 4.84 #2 Tue, 25 Nov 2014 11:31:45 +0100 | ||
+ | 220-We do not authorize the use of this system to transport unsolicited, | ||
+ | 220 and/or bulk e-mail. | ||
+ | type '' | ||
+ | | ||
+ | ===== Postfix configuration ===== | ||
- | Test your SMTPS tunnel | + | Install Postfix |
+ | apt-get install postfix | ||
+ | If you weren’t automatically prompted to configure Postfix, run sudo '' | ||
+ | Now edit ''/ | ||
+ | relayhost = [127.0.0.1]: | ||
+ | inet_interfaces = loopback-only | ||
+ | # SASL Settings | ||
+ | smtp_use_tls = yes | ||
+ | smtp_sasl_auth_enable = yes | ||
+ | smtp_sasl_password_maps = hash:/ | ||
+ | smtp_sasl_security_options = | ||
- | ==== Postfix configuration ==== | + | The SASL settings [1] point to a password file, which we haven' |
+ | vim / | ||
+ | and add | ||
+ | [127.0.0.1]: | ||
+ | Beware to keep the SASL client password file within / | ||
+ | So change owner (chown) and set permissions (chmod) on the file to 600 so that your password can't be read by others with | ||
+ | chown root:root / | ||
+ | chmod 600 / | ||
- | Put these lines in / | + | Finally convert the text-based password file to as hash-based file that Postfix can understand with |
+ | postmap | ||
- | relayhost = [127.0.0.1]: | + | Restart Postifix server |
- | inet_interfaces = loopback-only | + | sudo service |
- | # SASL Settings | + | |
- | smtp_use_tls = yes | + | |
- | smtp_sasl_auth_enable = yes | + | |
- | smtp_sasl_password_maps = hash:/etc/postfix/ | + | |
- | smtp_sasl_security_options = | + | |
- | The SASL settings point to a password file, which we haven' | + | ==== Important notes about password file ==== |
- | The last step is to provide Postfix with your username and password for the smarthost. Without authentication, | + | * Use the postmap command whenever |
+ | * If you specify the " | ||
+ | * If you specify a non-default TCP Port (such as ":submission" | ||
- | [127.0.0.1]: | + | ==== Address rewriting ==== |
- | Convert the text-based password file to as hash-based file that Postfix | + | Some hosts have no valid Internet domain name, and instead use a name such as localdomain.local or example.com. This can be a problem when you want to send mail over the Internet, because many mail servers reject mail addresses |
+ | You can specify generic lookup tables that replace local mail addresses by valid Internet addresses when mail leaves the machine via SMTP. | ||
- | sudo postmap / | + | Edit file ''/ |
+ | localuser@example.com | ||
+ | and hash it with | ||
+ | | ||
+ | Finally, add | ||
+ | smtp_generic_maps = hash:/ | ||
+ | to '' | ||
+ | For more info about address rewriting in Postfix see [2]. | ||
- | Restart both servers: | + | ===== Final testing ===== |
- | sudo service stunnel4 restart | + | At this point, the entire setup should be working. Send a test message from the command line to an external e-mail account (see [[notes: |
- | sudo service postfix reload | + | |
- | Send a test message | + | Install mailutils |
+ | | ||
+ | and run | ||
+ | echo This is a test message. | mail -s "Test Message" | ||
+ | while running | ||
+ | tail -f /var/log/mail.log | ||
+ | in a second terminal. | ||
- | At this point, the entire setup should be working. Try to send yourself a test message using echo This is a test message. | mail -s "Test Message" | + | If you see and error like |
+ | warning: SASL authentication failure: No worthy mechs found | ||
+ | you neet to install libsasl2-modules with | ||
+ | apt-get install libsasl2-modules | ||
- | http:// | + | [1] http:// |
- | http:// | + | [2] http:// |
- | http:// | + | [3] http:// |
+ | [4] http:// |
notes/postfix-stunnel-smtps.txt · Last modified: 2014/11/25 11:42 by admin