Error sending emails with an external email server

Hi,

I'm moving from an old server to linode and I'm having some problems when sending emails.

The email that I use is

MAIL_DRIVER=smtp

MAIL_HOST=smtp.example.com

MAIL_PORT=587

MAILFROMADDRESS=contact@example.com

MAILFROMNAME="Contact"

MAIL_PASSWORD=<*>

MAIL_ENCRYPTION=tls

When I try to send an email from my site I'm getting the error:

Connection could not be established with host smtp.example.com [Connection refused #111]

The smtp.example.com is an email server that I use from a long time and I don't want to use a new email server.

My project uses Laravel, both in my old server and in my local environment this configuration is working fine.

Laravel uses swiftmailer to send the emails.

How can I get my email working? I need to open some port or do something else?

Edit:

My linode is an ubuntu 16.04 LTS

3 Replies

Either your settings are incorrect (e.g. you're trying to use LMTP 587 but the server is actually configured for port 25), or there is a network/DNS problem or a firewall on the server side. My guess would be the latter; on servers that use LMTP on port 587, access to the port is typically restricted by an IP whitelist on the firewall. Ask the server owner to include your new IP in their whitelist.

Test whether you can actually connect to the port from your new Linode by performing telnet smtp.example.com 587. If you get a connection rejected message, then it is one of the above reasons. Otherwise your Swiftmailer code isn't configured correctly.

@emestee:

Either your settings are incorrect (e.g. you're trying to use LMTP 587 but the server is actually configured for port 25), or there is a network/DNS problem or a firewall on the server side. My guess would be the latter; on servers that use LMTP on port 587, access to the port is typically restricted by an IP whitelist on the firewall. Ask the server owner to include your new IP in their whitelist.

Test whether you can actually connect to the port from your new Linode by performing telnet smtp.example.com 587. If you get a connection rejected message, then it is one of the above reasons. Otherwise your Swiftmailer code isn't configured correctly.

I think the settings are correct because I can send emails from my local machine with the same configuration.

I tried the telnet and got the same message:

telnet: Unable to connect to remote host: Connection refused

So, as you told, probably there is a network/DNS problem or a firewall on the server side. I'll check there.

Thank you very much

Problem solved!

As @emestee pointed, the smtp server was blocking my access. I added my IP to the whitelist and it's ok now.

Thank you

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct