pkouadio's avatar

Sending mail connection refused

Hi, I am finishing the configuration for sending mail and I have an error that I can't explain. In fact, I have the following configuration:

'smtp' => [
    'transport' => 'smtp',
    'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
    'port' => env('MAIL_PORT', 587),
    'encryption' => env('MAIL_ENCRYPTION', 'tls'),
    'username' => env('MAIL_USERNAME'),
    'password' => env('MAIL_PASSWORD'),
    'timeout' => null,
    'auth_mode' => null,
    'stream' => [
	    'ssl' => [
		    'allow_self_signed' => true,
		    'verify_peer' => false,
		    'verify_peer_name' => false,
		    ],
		'tls' => [
			'allow_self_signed' => true,
			'verify_peer' => false,
			'verify_peer_name' => false,],
			],
	],

the .env file has the following parameters:

MAIL_MAILER=smtp
MAIL_HOST=live.smtp.mailtrap.io
MAIL_PORT=587
MAIL_USERNAME=api
MAIL_PASSWORD=mypass
MAIL_ENCRYPTION=tls
MAIL_SMTP_SSL=true
MAIL_SMTP_SSL_VERIFY_PEER=false
MAIL_SMTP_SSL_ALLOW_SELF_SIGNED=true
MAIL_FROM_ADDRESS=mysendmail
MAIL_FROM_NAME="${APP_NAME}"

But I still have this error:

Connection could not be established with host live.smtp.mailtrap.io :stream_soket_client():Unable to connect to tcp://live.smtp.mailtrap.io:587 (connection refused)

Thank you for your help.

0 likes
6 replies
LaryAI's avatar
Level 58

The error message "connection refused" suggests that the server is not able to connect to the specified host and port. This could be due to a firewall blocking the connection or the host and port being incorrect.

To troubleshoot this issue, try the following steps:

  1. Verify that the host and port are correct. In this case, the host is "live.smtp.mailtrap.io" and the port is "587". Double-check that these values are correct and that there are no typos.

  2. Check if there is a firewall blocking the connection. Try connecting to the host and port using a tool like Telnet or Netcat. For example, run the following command in the terminal:

telnet live.smtp.mailtrap.io 587

If the connection is successful, you should see a message like "220 smtp.mailtrap.io ESMTP ready". If the connection fails, it could be due to a firewall blocking the connection.

  1. Verify that the credentials are correct. In this case, the username is "api" and the password is "mypass". Double-check that these values are correct and that there are no typos.

  2. Try using a different mail server to see if the issue is specific to the current server. For example, you could try using Gmail's SMTP server to see if the issue persists.

If none of these steps resolve the issue, it may be helpful to contact the mail server provider for further assistance.

Snapey's avatar

Do you have a mailtrap account?

pkouadio's avatar

@Snapey Yes, I have an account and it works fine in test mode. But I can't send the mails in the normal mode.

pkouadio's avatar

@Snapey I have also done the DNS CNAME and TXT records requested, but it doesn't work.

Snapey's avatar
Snapey
Best Answer
Level 122

@pkouadio You cannot send emails using mailtrap. Only to their service. For real mail sending, you need a mail service provider

Once you have that, you can enter your real credentials in the .env file.

Please or to participate in this conversation.