Force TLS email traffic over port 587
Hello,
Currently, we have STARTTLS enabled on port 25 on Postal. I am aware that port 25 using STARTTLS functions perfectly fine. However, AcyMailing (a Joomla! plugin for newsletters and the like) refuses to send email over that port. For usage of TLS (or SSL for that matter) it requires email to be sent from either port 465 or 587, naturally, the latter being preferred.
This boils down to the question: how do we send TLS email from port 587, despite it functioning on port 25?
Thanks.
You can use iptables to forward traffic from 587 to 25.
We have port 2525 open as well as 25 to get around some SMTP restrictions.
Have a look at https://github.com/atech/postal/issues/306#issuecomment-321571866
I did that, now when I telnet into port 587:
MacBook-Pro-van-William-David:~ server$ telnet . 587 Trying .... Connected to .. Escape character is '^]'. 220 . ESMTP Postal/KVTSYX qui t502 Invalid/unsupported command quit 502 Invalid/unsupported command exit 502 Invalid/unsupported command
Not sure why, because it's just an iptables rule...
Does your plugin work in spite of the telnet issues?
Nope...
Does telnet work on port 25?
Yes, on port 25 it works perfectly fine and I'm able to negotiate using the openssl command. However, opening a telnet session to port 587 causes it to act weirdly like the output I posted above.
Could you try 2525 and see if telnet still works through that port?
Nope, connection refused. Same with firewall disabled.
I am unable to replicate your issues, I get working telnet with any forwarded port.
Which server provider are you using? Could there be any curious filtering occurring?
That is very odd. We're using Linode for this customer and I can assure you there is no filtering on any level.
Can you check with sudo netstat -lnp that nothing is listening on 587?
Hi,
I figured I'd send the entire output:
root@localhost:~# netstat -lnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 3456/sshd
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 3582/nginx -g daemo
tcp 0 0 127.0.0.1:5000 0.0.0.0:* LISTEN 3880/[postal] web.1
tcp 0 0 0.0.0.0:25672 0.0.0.0:* LISTEN 3475/beam
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 3764/mysqld
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3582/nginx -g daemo
tcp 0 0 0.0.0.0:4369 0.0.0.0:* LISTEN 3668/epmd
tcp6 0 0 :::22 :::* LISTEN 3456/sshd
tcp6 0 0 :::25 :::* LISTEN 3886/[postal] smtp.
tcp6 0 0 :::443 :::* LISTEN 3582/nginx -g daemo
tcp6 0 0 :::5672 :::* LISTEN 3475/beam
tcp6 0 0 :::80 :::* LISTEN 3582/nginx -g daemo
tcp6 0 0 :::4369 :::* LISTEN 3668/epmd
Active UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node PID/Program name Path
unix 2 [ ACC ] STREAM LISTENING 8717 1/init /run/systemd/private
unix 2 [ ACC ] STREAM LISTENING 8735 1/init /run/systemd/journal/stdout
unix 2 [ ACC ] STREAM LISTENING 14915 3764/mysqld /var/run/mysqld/mysqld.sock
unix 2 [ ACC ] STREAM LISTENING 13139 1/init /run/uuidd/request
unix 2 [ ACC ] STREAM LISTENING 15709 3938/systemd /run/user/0/systemd/private
unix 2 [ ACC ] STREAM LISTENING 13149 1/init /var/run/dbus/system_bus_socket
unix 2 [ ACC ] STREAM LISTENING 8870 1/init /run/systemd/fsck.progress
unix 2 [ ACC ] SEQPACKET LISTENING 8874 1/init /run/udev/control
unix 2 [ ACC ] STREAM LISTENING 14871 3874/app) /tmp/postal/pids/procodile.sock
When grepping on 587 there is no output:
root@localhost:~# netstat -lnp | grep 587
root@localhost:~#
Going back a few steps....
Nope, connection refused. Same with firewall disabled.
Did you run the iptables rules for port 2525?
No, I have not. Why would I? I don't have a firewall.
By the way, there is nothing listening on port 2525 either:
root@localhost:/opt/postal# netstat -lnp | grep 2525
root@localhost:/opt/postal#
iptables is a way of forwarding the traffic as well as a firewall. If you can try the rules suggested earlier and forward port 2525 to port 25 then see if telnet works.
If you have used iptables to forward both 2525 and 587 and telnet works on 2525 but not 587, you know something is blocking you somehow somewhere.
Does that make sense?
Apologies! Probably a lack of sleep :)
I disabled the firewall completely to see what'd happen. To my surprise, port 587 still works, but not with SSL...
I setup iptables to forward port 2525 to 25, which works:
MacBook-Pro-van-William-David:~ server$ telnet . 2525
Trying ....
Connected to ..
Escape character is '^]'.
220 . ESMTP Postal/F1GFJY
However, like I mentioned, SSL does not work. Without SSL everything functions fine.
MacBook-Pro-van-William-David:~ server$ openssl s_client -connect .:587 -ssl3
CONNECTED(00000003)
3720:error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number:/BuildRoot/Library/Caches/com.apple.xbs/Sources/OpenSSL098/OpenSSL098-59.60.1/src/ssl/s3_pkt.c:300:
MacBook-Pro-van-William-David:~ server$ openssl s_client -connect .:2525 -ssl3
CONNECTED(00000003)
3721:error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version
number:/BuildRoot/Library/Caches/com.apple.xbs/Sources/OpenSSL098/OpenSSL098-
59.60.1/src/ssl/s3_pkt.c:300:
So I figured that might be a problem on my system. I tried that same command on a server, which does not work either, returning:
[root@server admin]# openssl s_client -connect .:587 -ssl3
CONNECTED(00000003)
140353024309152:error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version
number:s3_pkt.c:365:
The entire output:
[root@server admin]# openssl s_client -connect .:587 -ssl3
CONNECTED(00000003)
140353024309152:error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version
number:s3_pkt.c:365:
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 5 bytes and written 7 bytes
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
Protocol : SSLv3
Cipher : 0000
Session-ID:
Session-ID-ctx:
Master-Key:
Key-Arg : None
Krb5 Principal: None
PSK identity: None
PSK identity hint: None
Start Time: 1507128981
Timeout : 7200 (sec)
Verify return code: 0 (ok)
---
Ah have you configured a certificate in postal.yml? Have a look at the default settings here:
https://github.com/atech/postal/blob/2a9702ba475b4703540e3edbe9de702b6f4a1dbe/config/postal.defaults.yml#L66
We manually created a letsencrypt certificate for the server so just recycled that:
smtp_server:
tls_enabled: true
tls_certificate_path: /etc/letsencrypt/live/postal.example.com/fullchain.pem
tls_private_key_path: /etc/letsencrypt/live/postal.example.com/privkey.pem
Yep, definitely, although it is self-signed (but that shouldn't be a problem). I appended the last three lines from the default settings (proxy_protocol, log_connect and strip_received_headers) and after restarting Postal this gives me another error:
MacBook-Pro-van-William-David:~ server$ openssl s_client -connect .:587 -starttls smtp
CONNECTED(00000003)
write:errno=54
Configuration:
smtp_server:
port: 25
tls_enabled: true
tls_certificate_path: config/fast_server.cert
tls_private_key_path: config/fast_server.key
proxy_protocol: false
log_connect: true
strip_received_headers: false
If you aren't changing the values, there shouldn't be a need to include the defaults I would have hoped!
Have you verified that certificate file exists? There have been some .cert/.crt mix ups recently.