Auryn Vansteenkiste
Auryn Vansteenkiste

Reputation: 57

Laravel & Cpanel: how to fix Swift_TransportException (mail server)?

When deploying laravel project and putting it online on the server im facing this error when trying to send an email:

"Swift_TransportException Connection could not be established with host smtp.mailtrap.io :stream_socket_client(): unable to connect to tcp://smtp.mailtrap.io:2525 (Connection refused)"

enter image description here

I tried switching ports but that doesn't work.

Laravel current env settings:

MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=user
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls

Anyone has any recommendations of what I may try to fix this issue ?

Thanks in advance !

Upvotes: 0

Views: 713

Answers (1)

user16354366
user16354366

Reputation:

Your best bet will be to use some network diagnostic utilities to find out where the block originates from, and then either update the corresponding firewall or fix the network problem.

  1. Login to the server via SSH or Terminal as the root user

  2. Install mtr with: yum install mtr -y

  3. First run an MTR test as root:

    mtr --tcp --port 2525 --report --report-cycles 10 smtp.mailtrap.io

  4. How many hops do you see pop up? If it is just one, the block is likely from your own local firewall. Only 2 hops might be your service provider. As for packet loss, latency etc etc, those are great to understand but outside of the scope of this. Linode has a top notch mtr guide if you need.

  5. If you didn't find any block from that MTR run, run the same exact command after you switch to the cPanel user that owns the SMTP script:

su -l -s /bin/bash cpanelusernamehere
mtr --tcp --port 2525 --report --report-cycles 10 smtp.mailtrap.io
  1. Again how many hops? Which node appears to be performing the block?

If the connection is legitimately making it all the way to smtp.mailtrop.io before being refused, you'd want to ask them to check into it for you.

If it still isn't obvious what's happening, you might be able to eek out some additional clues with telnet and nmap:

yum install telnet nmap -y 
nmap -p 2525 smtp.mailtrap.io
telnet smtp.mailtrap.io 2525

Upvotes: 1

Related Questions