postal icon indicating copy to clipboard operation
postal copied to clipboard

Can't connect to SMTP

Open adepondra opened this issue 8 years ago • 14 comments

Hi, I have issue to connect smtp server, all setting is configure as well and i can sent email perfectly trough postal but we want use postal as a relay email so i need to connect to SMTP. I have create credentials but i cannot connected to the SMTP via our app. How to fix it? my postal.yml

smtp: Specify an SMTP server that can be used to send messages from the Postal management system to users. You can configure this to use a Postal mail server once the your installation has been set up. host: post.mydomain.com port: 25 username: # Complete when Postal is running and you can password: # generate the credentials within the interface. from_name: Post Email from_address: [email protected]

The telnet result

Trying 23.101.xxx.101... Connected to post.mydomain.com. Escape character is '^]'. 220 post.mydomain.com ESMTP Postal/VGQ8WS`

My Postal Status

|| web || Quantity 1 || Command bundle exec puma -C config/puma.rb || Respawning 5 every 3600 seconds || Restart mode usr1 || Log path none specified || Address/Port none || => web.1 Running 14:16 pid:22936 respawns:0 port:- tag:-

|| worker || Quantity 1 || Command bundle exec ruby script/worker.rb || Respawning 5 every 3600 seconds || Restart mode start-term || Log path none specified || Address/Port none || => worker.2 Running 14:48 pid:25596 respawns:0 port:- tag:-

|| cron || Quantity 1 || Command bundle exec rake postal:cron || Respawning 5 every 3600 seconds || Restart mode term-start || Log path none specified || Address/Port none || => cron.2 Running 14:48 pid:25610 respawns:0 port:- tag:-

|| smtp || Quantity 1 || Command bundle exec rake postal:smtp_server || Respawning 5 every 3600 seconds || Restart mode usr1 || Log path none specified || Address/Port none || => smtp.1 Running 14:49 pid:25600 respawns:0 port:- tag:-

|| requeuer || Quantity 1 || Command bundle exec rake postal:requeuer || Respawning 5 every 3600 seconds || Restart mode term-start || Log path none specified || Address/Port none || => requeuer.2 Running 14:48 pid:25611 respawns:0 port:- tag:-

My netstat -lnp result

Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:783 0.0.0.0:* LISTEN 10241/perl tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 27993/nginx: master tcp 0 0 0.0.0.0:4369 0.0.0.0:* LISTEN 9092/epmd tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 784/systemd-resolve tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1428/sshd tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 27993/nginx: master tcp 0 0 127.0.0.1:5000 0.0.0.0:* LISTEN 22936/[postal] web. tcp 0 0 0.0.0.0:25672 0.0.0.0:* LISTEN 9007/beam.smp tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 8707/mysqld tcp6 0 0 ::1:783 :::* LISTEN 10241/perl tcp6 0 0 :::80 :::* LISTEN 27993/nginx: master tcp6 0 0 :::4369 :::* LISTEN 9092/epmd tcp6 0 0 :::22 :::* LISTEN 1428/sshd tcp6 0 0 :::25 :::* LISTEN 25600/[postal] smtp tcp6 0 0 :::443 :::* LISTEN 27993/nginx: master tcp6 0 0 :::5672 :::* LISTEN 9007/beam.smp udp 30720 0 127.0.0.53:53 0.0.0.0:* 784/systemd-resolve udp 0 0 10.0.1.4:68 0.0.0.0:* 769/systemd-network raw6 0 0 :::58 :::* 7 769/systemd-network Active UNIX domain sockets (only servers) Proto RefCnt Flags Type State I-Node PID/Program name Path unix 2 [ ACC ] SEQPACKET LISTENING 1411 1/init /run/udev/control unix 2 [ ACC ] STREAM LISTENING 189807 19545/systemd /run/user/1000/systemd/private unix 2 [ ACC ] STREAM LISTENING 189811 19545/systemd /run/user/1000/gnupg/S.dirmngr unix 2 [ ACC ] STREAM LISTENING 189812 19545/systemd /run/user/1000/gnupg/S.gpg-agent.browser unix 2 [ ACC ] STREAM LISTENING 189813 19545/systemd /run/user/1000/gnupg/S.gpg-agent.extra unix 2 [ ACC ] STREAM LISTENING 189814 19545/systemd /run/user/1000/gnupg/S.gpg-agent unix 2 [ ACC ] STREAM LISTENING 189815 19545/systemd /run/user/1000/gnupg/S.gpg-agent.ssh unix 2 [ ACC ] STREAM LISTENING 231885 22930/[procodile] P /tmp/postal/pids/procodile.sock unix 2 [ ACC ] STREAM LISTENING 16749 1/init /var/lib/lxd/unix.socket unix 2 [ ACC ] STREAM LISTENING 16738 1/init /var/run/dbus/system_bus_socket unix 2 [ ACC ] STREAM LISTENING 16270 1061/irqbalance @irqbalance1061.sock unix 2 [ ACC ] STREAM LISTENING 16751 1/init /run/acpid.socket unix 2 [ ACC ] STREAM LISTENING 16752 1/init /run/snapd.socket unix 2 [ ACC ] STREAM LISTENING 16754 1/init /run/snapd-snap.socket unix 2 [ ACC ] STREAM LISTENING 16757 1/init /run/uuidd/request unix 2 [ ACC ] STREAM LISTENING 1335 1/init /run/systemd/private unix 2 [ ACC ] STREAM LISTENING 1352 1/init /run/lvm/lvmetad.socket unix 2 [ ACC ] STREAM LISTENING 732424 9351/gpg-agent /var/lib/spamassassin/sa-update-keys/S.gpg-agent unix 2 [ ACC ] STREAM LISTENING 1357 1/init /run/systemd/journal/stdout unix 2 [ ACC ] STREAM LISTENING 732425 9351/gpg-agent /var/lib/spamassassin/sa-update-keys/S.gpg-agent.extra unix 2 [ ACC ] STREAM LISTENING 732426 9351/gpg-agent /var/lib/spamassassin/sa-update-keys/S.gpg-agent.browser unix 2 [ ACC ] STREAM LISTENING 732427 9351/gpg-agent /var/lib/spamassassin/sa-update-keys/S.gpg-agent.ssh unix 2 [ ACC ] STREAM LISTENING 12363 1/init /run/lvm/lvmpolld.socket unix 2 [ ACC ] STREAM LISTENING 220933 8707/mysqld /var/run/mysqld/mysqld.sock unix 2 [ ACC ] STREAM LISTENING 16737 1/init @ISCSIADM_ABSTRACT_NAMESPACE

adepondra avatar Nov 14 '18 04:11 adepondra

@adepondra can you also provide some smtp_sender and smtp_server logs?

joeneldeasis avatar Nov 14 '18 06:11 joeneldeasis

Here the smtp_sender

Logfile created on 2018-11-13 15:42:50 +0000 by logger.rb/56438 [worker.2:25596] [2018-11-13T15:42:50.546] INFO -- : [OD22BSXP] Cannot connect to 2404:6800:4003:c04::1b:25 (gmail-smtp-in.l.google.com) (Errno::ENETUNREACH: Network is unreachable - connect(2) for "2404:6800:4003:c04::1b" port 25) [worker.2:25596] [2018-11-13T15:42:51.290] INFO -- : [OD22BSXP] Connected to 172.217.194.26:25 (gmail-smtp-in.l.google.com) [worker.2:25596] [2018-11-13T15:42:51.290] INFO -- : [OD22BSXP] Sending message 1::1 to [email protected] [worker.2:25596] [2018-11-13T15:42:53.306] INFO -- : [OD22BSXP] Message sent #1 to gmail-smtp-in.l.google.com (172.217.194.26) for [email protected] [worker.2:25596] [2018-11-13T15:42:53.375] INFO -- : [OD22BSXP] Finishing up [worker.2:25596] [2018-11-13T15:48:10.671] INFO -- : [Z0C67EZW] Connected to 94.23.206.89:25 (mail-tester.com) [worker.2:25596] [2018-11-13T15:48:10.672] INFO -- : [Z0C67EZW] Sending message 1::2 to [email protected] [worker.2:25596] [2018-11-13T15:48:11.689] INFO -- : [Z0C67EZW] Message sent #2 to mail-tester.com (94.23.206.89) for [email protected] [worker.2:25596] [2018-11-13T15:48:11.774] INFO -- : [Z0C67EZW] Finishing up [worker.2:25596] [2018-11-13T23:50:33.519] INFO -- : [JAPYAVJH] Cannot connect to 2404:6800:4003:c04::1b:25 (gmail-smtp-in.l.google.com) (Errno::ENETUNREACH: Network is unreachable - connect(2) for "2404:6800:4003:c04::1b" port 25) [worker.2:25596] [2018-11-13T23:50:34.312] INFO -- : [JAPYAVJH] Connected to 172.217.194.27:25 (gmail-smtp-in.l.google.com) [worker.2:25596] [2018-11-13T23:50:34.312] INFO -- : [JAPYAVJH] Sending message 1::3 to [email protected] [worker.2:25596] [2018-11-13T23:50:35.188] INFO -- : [JAPYAVJH] Message sent #3 to gmail-smtp-in.l.google.com (172.217.194.27) for [email protected] [worker.2:25596] [2018-11-13T23:50:35.257] INFO -- : [JAPYAVJH] Finishing up

smtp_server log

Logfile created on 2018-11-13 14:16:29 +0000 by logger.rb/56438 [smtp.1:22945] [2018-11-13T14:16:29.469] INFO -- : Listening on port 25 [smtp.1:25600] [2018-11-13T14:49:00.600] INFO -- : Listening on port 25 [smtp.1:25600] [2018-11-14T01:47:04.054] DEBUG -- : [H5XSHH]  Connection opened from ::ffff:23.101.23.101 [smtp.1:25600] [2018-11-14T01:47:04.054] DEBUG -- : [H5XSHH]  Client identified as ::ffff:23.101.23.101 [smtp.1:25600] [2018-11-14T02:18:31.227] DEBUG -- : [JIAP5T]  Connection opened from ::ffff:162.243.157.180 [smtp.1:25600] [2018-11-14T02:18:31.228] DEBUG -- : [JIAP5T]  Client identified as ::ffff:162.243.157.180 [smtp.1:25600] [2018-11-14T02:18:31.228] DEBUG -- : [JIAP5T] <= EHLO zg-1112c-39 [smtp.1:25600] [2018-11-14T02:18:31.401] DEBUG -- : [JIAP5T] => 250-My capabilities are [smtp.1:25600] [2018-11-14T02:18:31.402] DEBUG -- : [JIAP5T] => 250 AUTH CRAM-MD5 PLAIN LOGIN [smtp.1:25600] [2018-11-14T02:18:41.052] DEBUG -- : [JIAP5T]  Connection closed [smtp.1:25600] [2018-11-14T03:36:36.912] DEBUG -- : [H5XSHH] <=  [smtp.1:25600] [2018-11-14T03:36:36.912] DEBUG -- : [H5XSHH] => 502 Invalid/unsupported command [smtp.1:25600] [2018-11-14T03:36:41.744] DEBUG -- : [H5XSHH] <=  [smtp.1:25600] [2018-11-14T03:36:41.744] DEBUG -- : [H5XSHH] => 502 Invalid/unsupported command [smtp.1:25600] [2018-11-14T03:36:42.289] DEBUG -- : [H5XSHH] <=  [smtp.1:25600] [2018-11-14T03:36:42.290] DEBUG -- : [H5XSHH] => 502 Invalid/unsupported command [smtp.1:25600] [2018-11-14T03:36:57.183] DEBUG -- : [H5XSHH] => 502 Invalid/unsupported command [smtp.1:25600] [2018-11-14T04:03:13.334] DEBUG -- : [H5XSHH] <=  [smtp.1:25600] [2018-11-14T04:03:13.334] DEBUG -- : [H5XSHH] => 502 Invalid/unsupported command [smtp.1:25600] [2018-11-14T04:03:17.316] DEBUG -- : [H5XSHH] <= quit [smtp.1:25600] [2018-11-14T04:03:17.317] DEBUG -- : [H5XSHH] => 221 Closing Connection [smtp.1:25600] [2018-11-14T04:03:17.317] DEBUG -- : [H5XSHH]  Connection closed [smtp.1:25600] [2018-11-14T04:13:58.369] DEBUG -- : [VGQ8WS]  Connection opened from ::ffff:23.101.23.101 [smtp.1:25600] [2018-11-14T04:13:58.369] DEBUG -- : [VGQ8WS]  Client identified as ::ffff:23.101.23.101 [smtp.1:25600] [2018-11-14T04:15:00.857] DEBUG -- : [VGQ8WS] => 502 Invalid/unsupported command [smtp.1:25600] [2018-11-14T04:15:03.327] DEBUG -- : [VGQ8WS] <= quit [smtp.1:25600] [2018-11-14T04:15:03.327] DEBUG -- : [VGQ8WS] => 221 Closing Connection [smtp.1:25600] [2018-11-14T04:15:03.327] DEBUG -- : [VGQ8WS]  Connection closed

adepondra avatar Nov 14 '18 06:11 adepondra

Can it be a firewall problem? I don't see the port you're connecting to in the telnet connection. I had a similar issue months ago and the problem was the Linux server internal firewall, that was enabling local connections to port 25 but rejecting outside connections.

cmmata avatar Nov 14 '18 09:11 cmmata

@cmmata can you tell me how to fix the firewall issue?

adepondra avatar Nov 14 '18 11:11 adepondra

@adepondra It depends on your system. Which distro do you have? In my case, it's a CentOS7 and the firewall running there is firewalld. If it's your case, you can:

  • See opened ports with firewall-cmd --list-all. Should show a list like this:
...
ports: 80/tcp 25/tcp 443/tcp
...
  • Open ports with firewall-cmd --add-port=25/tcp --permanent and then firewall-cmd --reload. (I'm writing this without trying in the server, it may have a syntax error or something). If it's another distro or don't have firewalld, you'll probably have iptables directly. If that's the case and don't know how to use it, reply here and I'll try to find the syntax.

cmmata avatar Nov 14 '18 12:11 cmmata

@cmmata I use Ubuntu 18.04. I have tried to disable UFW (ubuntu firewall) and add port 25 open to iptables using this comment sudo iptables -A INPUT -i lo -j ACCEPT sudo iptables -A OUTPUT -o lo -j ACCEPT sudo iptables -A INPUT -p tcp --dport 25 -j ACCEPT

sudo netfilter-persistent save sudo netfilter-persistent reload

But still cannot connect to SMTP. I'm confused how to fix it.

adepondra avatar Nov 14 '18 14:11 adepondra

If you list your iptables rules (iptables -L), do you see port 25 listed? Anyway, just curious, why did you disable UFW and go with iptables? UFW seems more user-friendly, and as it's the default firewall in ubuntu it may be re-enabled after a reboot or package update.

cmmata avatar Nov 14 '18 15:11 cmmata

@cmmata yes, i see port 25 in the list. Because i not familiar with ubuntu firewall, i usually using centos for my server, the first articles i got about ubuntu firewall is how to enable and disable it so just for quick solution test i try to disabled it. hahaha.. I read the documentation of postal i think this app only can installed to ubuntu.

adepondra avatar Nov 15 '18 07:11 adepondra

I'm using it in a CentOS7 server, so I can assure it's not only for Ubuntu ;) I think Ubuntu may be the server Postal developers are using and they recommend it. You just need to make some extra steps like configuring selinux or stuff like that.

Anyway, are you in the same network as your server? Or is the server in a public cloud? If it's in a cloud, maybe your provider have a firewall too and is blocking that port.

cmmata avatar Nov 15 '18 09:11 cmmata

@cmmata I installed in azure vm and the port of 25 is open for inbound and outbound traffic. I can send email via postal directly. But i still cannot connect to SMTP

adepondra avatar Nov 15 '18 10:11 adepondra

I have just realized that your netstat shows you're using ipv6. Can it be the same problem as #435?

cmmata avatar Nov 15 '18 16:11 cmmata

For your information, processes listening on IPv6 (tcp6) can listen on IPv4 (tcp) simultaneously which is why it only appears once in netstat.

I'd agree with the earlier assumption that there is an external block somewhere. It could be worth trying a different port instead of 25 just to verify connection is possible sometimes.

willpower232 avatar Nov 15 '18 16:11 willpower232

@cmmata I have move to new server and installed fresh postal and applied some of your recommendation. Now postal listening port 25 using ipv4 (following #435 to change '::' to '0.0.0.0') and add port 25 to be open to iptables. But i still cannot connect to SMTP.

@willpower232 how to change listening postal SMTP port? i'm not expert in linux need some tutorial to do it.

if i try to use telnet post.domian.com 25 the status is connected. Here the result

Trying 207.180.xx.xxx... Connected to post.domain.com. Escape character is '^]'. 220 post.domain.com ESMTP Postal/URQ8CH quit 221 Closing Connection Connection closed by foreign host.

my iptables rules

root@vmi226551:~# iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT tcp -- anywhere anywhere tcp dpt:ssh ACCEPT tcp -- anywhere anywhere tcp dpt:smtp ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination

my netstat -lnp result:

root@vmi226551:~# netstat -lnp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:5000 0.0.0.0:* LISTEN 1293/[postal] web.1 tcp 0 0 0.0.0.0:25672 0.0.0.0:* LISTEN 891/beam.smp tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 1170/mysqld tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1038/nginx -g daemo tcp 0 0 0.0.0.0:4369 0.0.0.0:* LISTEN 1000/epmd tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1007/sshd tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 1299/[postal] smtp. tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 1038/nginx -g daemo tcp6 0 0 :::5672 :::* LISTEN 891/beam.smp tcp6 0 0 :::80 :::* LISTEN 1038/nginx -g daemo tcp6 0 0 :::4369 :::* LISTEN 1000/epmd tcp6 0 0 :::22 :::* LISTEN 1007/sshd tcp6 0 0 :::443 :::* LISTEN 1038/nginx -g daemo Active UNIX domain sockets (only servers)

adepondra avatar Nov 29 '18 15:11 adepondra

We run Postal on 25 by default and then forward traffic from another port too to guarantee access.

Have a look at https://github.com/atech/postal/issues/306#issuecomment-321571866

willpower232 avatar Dec 03 '18 10:12 willpower232