I'm trying to set Mailgun up on Craft (Like we've done plenty of times before) but each time it keeps saying that the connection to SMTP is failing.

The error I'm getting is:

2017/03/29 09:54:13 [error] [application] Email error: SMTP Error: Could not authenticate.

I've checked https://craftcms.com/support/troubleshooting-email-errors#dealing-with-errors and error description is:

“Use SMTP authentication” was checked, but the credentials were incorrect.

But I've double checked these details over 10x now and they are 100% correct.

Is there any other reason this could fail? We're using port 587 and tried other ports but no success. Even opening these ports on the server doesn't connect.

Where would the problem be... Craft, Mailgun or Server?

2 Answers 2


Craft is just passing on the error message it gets back when trying to connect with whatever settings it was given.

And we're using Mailgun ourselves (port 587) for sending emails on https://craftcms.com, which is a Craft install.

Make sure you're using smtp.mailgun.org as the host and that you've got the transport type set to TLS as well.

  • Do I need to change any settings for the TLS to work in MailGun? I did think it was a connection issue though.
    – Jason Mayo
    Mar 29, 2017 at 15:25
  • I don't recall us having to change anything at all.
    – Brad Bell
    Mar 29, 2017 at 21:07

So it turns out this was a server issue due to cPanel... A few solutions for people may run in to this in future...

As well as this:

This will likely be being caused by a cPanel configuration item which redirects outbound traffic on SMTP ports from non-root users back to localhost.

So, when attempting to connect to smtp.mailgun.org, you are silently redirected to, which then fails to authenticate.

This is uaually used in shared hosting environment to limit the impact of compromised scripts sending out SPAM on the server.

I've disabled this in WHM > Server Configuration > Tweak Settings > Mail > "Restrict outgoing SMTP to root, exim, and mailman (FKA SMTP Tweak)" and setting this to "Off".

Fixed! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.