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

<p>And we're using Mailgun ourselves (port 587) for sending emails on <a href="https://craftcms.com" rel="noreferrer">https://craftcms.com</a>, which is a Craft install.</p>

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

CC BY-SA 3.0
2017-03-29T15:25:41.083Z
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
CC BY-SA 3.0
2017-03-29T21:07:53.443Z
I don't recall us having to change anything at all.
Brad Bell
CC BY-SA 3.0
2017-03-29T15:08:30.907Z
2017-03-29T15:08:30.907Z
Brad Bell
<p>So it turns out this was a server issue due to cPanel... A few solutions for people may run in to this in future...</p>

<ul>
<li>Set email settings to remote on server</li>
<li>Update MX entries on server</li>
<li>Add postmaster@ and site@ mailboxes via cPanel</li>
<li>Added this to EXIM config - <a href="https://grepitout.com/configure-mailgun-cpanel-exim/" rel="nofollow noreferrer">https://grepitout.com/configure-mailgun-cpanel-exim/</a></li>
</ul>

<p>As well as this:</p>

<blockquote>
  <p>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.</p>
  
  <p>So, when attempting to connect to smtp.mailgun.org, you are silently redirected to 127.0.0.1, which then fails to
  authenticate.</p>
  
  <p>This is uaually used in shared hosting environment to limit the impact of compromised scripts sending out SPAM on the
  server.</p>
  
  <p>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".</p>
</blockquote>

<p>Fixed! :)</p>

CC BY-SA 3.0
2017-04-11T14:43:01.993Z
2017-04-11T14:43:01.993Z
Jason Mayo
<p>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. </p>

<p>The error I'm getting is:</p>

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

<p>I've checked <a href="https://craftcms.com/support/troubleshooting-email-errors#dealing-with-errors" rel="nofollow noreferrer">https://craftcms.com/support/troubleshooting-email-errors#dealing-with-errors</a> and error description is:</p>

<blockquote>
  <p>“Use SMTP authentication” was checked, but the credentials were incorrect.</p>
</blockquote>

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

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

<p>Where would the problem be... Craft, Mailgun or Server?</p>

<emails>
Mailgun (SMTP) + Craft
# Mailgun (SMTP) + Craft

(Asked by: username_0 on 2017-03-29)

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?

**Tags:** emails


---

## 2 answers

### Answer by username_0 on 2017-04-11. Score: 4 | Accepted answer

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

* Set email settings to remote on server
* Update MX entries on server
* Add postmaster@ and site@ mailboxes via cPanel
* Added this to EXIM config - <https://grepitout.com/configure-mailgun-cpanel-exim/>

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 127.0.0.1, 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! :)


---

### Answer by username_1 on 2017-03-29. Score: 5

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.

> **Comments:**
> **username_0**: Do I need to change any settings for the TLS to work in MailGun? I did think it was a connection issue though.  
> **username_1**: I don't recall us having to change anything at all.  

---

