Mautic SMTP connection refused

We had recent situations where the clients reported that they are not able to properly configure the SMTP settings in Mautic. The reported error is:

Connection could not be established with host email-smtp.us-east-1.amazonaws.com :stream_socket_client(): unable to connect to tcp://email-smtp.us-east-1.amazonaws.com:25 (Connection refused) Log data: ++ Starting Mautic\EmailBundle\Swiftmailer\Transport\AmazonTransport !! Connection could not be established with host email-smtp.us-east-1.amazonaws.com :stream_socket_client(): unable to connect to tcp://email-smtp.us-east-1.amazonaws.com:25 (Connection refused) (code: 0)
++ Starting Mautic\EmailBundle\Swiftmailer\Transport\AmazonTransport !! Connection could not be established with host email-smtp.us-east-1.amazonaws.com :stream_socket_client(): unable to connect to tcp://email-smtp.us-east-1.amazonaws.com:25 (Connection refused) (code: 0)
mautic smtp settings
Mautic Mail Send Settings

How to deal with this issue? First of all, you must check if port 587 (25, 465) is open in your firewall.

If you are using cPanel/WHM check if the Restrict outgoing SMTP to root, exim, and mailman (FKA SMTP Tweak) option in WHM >> Server Configuration >> Tweak Settings is enabled or not. Notice that if the option is enabled, you – as root, will be able to connect to the remote SMTP server (Amazon in this case) but the client may still have issues.

root@web [~]# telnet email-smtp.us-east-1.amazonaws.com 587
Trying 52.205.70.65...
Connected to email-smtp.us-east-1.amazonaws.com.
Escape character is '^]'.
220 email-smtp.amazonaws.com ESMTP SimpleEmailService-d-W7XKCH9I6 C7jLCsIBSUGucJnbYgC8
quit
221 Bye
Connection closed by foreign host.
root@web [~]#

In our case, the WHM option was disabled. The connections were blocked by the SMTP_BLOCK = "1" option in the CSF settings.

Block outgoing SMTP except for root, exim and mailman (forces scripts/users to use the exim/sendmail binary instead of sockets access). This replaces the protection as WHM > Tweak Settings > SMTP Tweaks

csf configuration file

To allow users to bypass the SMTP block rule, you must add them to SMTP_ALLOWUSER field. Add them from the graphical interface in WHM >> Plugins >> ConfigServer Security & Firewall >> Firewall Configuration or edit the file /etc/csf/csf.conf from the command line.

SMTP_ALLOWUSER = "cpanel,plothosttest"
root@web [~]# grep SMTP_ALLOWUSER /etc/csf/csf.conf
SMTP_ALLOWUSER = "cpanel,plothosttest"
root@web [~]#

Are you looking for a Mautic host? Check out our Mautic web hosting plans.

References:
Amazon SMTP connectivity or timeout issues

Leave a Reply