# Email does not work; Net::SMTPAuthenticationError

**URL:** https://meta.discourse.org/t/email-does-not-work-net-smtpauthenticationerror/317828
**Category:** Self-hosting
**Tags:** email
**Created:** [July 23, 2024, 12:48pm UTC](https://meta.discourse.org/t/email-does-not-work-net-smtpauthenticationerror/317828 "2024-07-23T12:48:44Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![wal](https://avatars.discourse-cdn.com/v4/letter/w/d6d6ee/32.png) [@wal](https://meta.discourse.org/u/wal)
#### Post date: [July 23, 2024, 12:48pm UTC](https://meta.discourse.org/t/email-does-not-work-net-smtpauthenticationerror/317828/1 "2024-07-23T12:48:44Z")

</div>

I am hosting the Discourse server on DigitalOcean, domain from PorkBun, mail server with MailGun.

My MailGun account is activated and the domain (`discourse.mydomain.com`) is verified for use with `mg.mydomain.com`. All the DNS TXT records are in place.

I have done every single troubleshooting step in the thread here multiple time; [Troubleshoot email on a new Discourse install](https://meta.discourse.org/t/troubleshoot-email-on-a-new-discourse-install/16326)

I can enter `telnet` on the host and send email manually without issue ([https://serverfault.com/questions/49935/easiest-way-to-send-a-test-email-from-a-server-to-test-settings](https://serverfault.com/questions/49935/easiest-way-to-send-a-test-email-from-a-server-to-test-settings))

The `app.yml` has these contents

```yaml
  DISCOURSE_DEVELOPER_EMAILS: 'myemail@gmail.com'
  DISCOURSE_SMTP_ADDRESS: smtp.mailgun.org
  DISCOURSE_SMTP_PORT: 587
  DISCOURSE_SMTP_USER_NAME: mail
  DISCOURSE_SMTP_PASSWORD: "12345678901234567890"
  DISCOURSE_SMTP_DOMAIN: mg.mydomain.com
  DISCOURSE_NOTIFICATION_EMAIL: admin@mg.mydomain.com

```

When I try to run `discourse-doctor` or if I run `./launcher enter app` then run `rake 'emails:test[mail@mg.mydomain.com]'` I get the following error

```plaintext
======================================== ERROR ========================================
                                    UNEXPECTED ERROR

Net::SMTPAuthenticationError

====================================== SOLUTION =======================================
This is not a common error. No recommended solution exists!

Please report the exact error message above to https://meta.discourse.org/
(And a solution, if you find one!)
=======================================================================================

```

Something is broken on Discourse, because I have no trouble sending the mail manually. I have been searching Google and the forums here for many hours, no solutions yet. Any ideas?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [July 23, 2024, 4:47pm UTC](https://meta.discourse.org/t/email-does-not-work-net-smtpauthenticationerror/317828/2 "2024-07-23T16:47:16Z")

</div>

Something is wrong with your username/password. It’s possible that your password has a character that needs escaping like a star or a single quote, maybe (so it’ll be easiest to change the password not to include that character).

See [Troubleshoot email on a new Discourse install](https://meta.discourse.org/t/troubleshoot-email-on-a-new-discourse-install/16326)

---

<div class="post-metadata">

### Author: ![wal](https://avatars.discourse-cdn.com/v4/letter/w/d6d6ee/32.png) [@wal](https://meta.discourse.org/u/wal)
#### Post date: [July 23, 2024, 8:18pm UTC](https://meta.discourse.org/t/email-does-not-work-net-smtpauthenticationerror/317828/3 "2024-07-23T20:18:23Z")

</div>

the password does not contain any of those characters. In fact its the auto-generated password from MailGun, and only has letters and numbers and a few ‘-’ characters. Its quite long.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [July 23, 2024, 8:20pm UTC](https://meta.discourse.org/t/email-does-not-work-net-smtpauthenticationerror/317828/4 "2024-07-23T20:20:07Z")

</div>

That was my best guess. I’d try generating a new password and/or copy-pasting it again. The likelihood that this is a bug in Discourse is extremely remote.

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [July 23, 2024, 8:29pm UTC](https://meta.discourse.org/t/email-does-not-work-net-smtpauthenticationerror/317828/5 "2024-07-23T20:29:59Z")

</div>

> [@wal](#):
>
> ```plaintext
> DISCOURSE_SMTP_USER_NAME: mail
> DISCOURSE_SMTP_PASSWORD: "12345678901234567890"
> DISCOURSE_SMTP_DOMAIN: mg.mydomain.com
> 
> ```

I’d wager `DISCOURSE_SMTP_USER_NAME` is incorrect - `mail` is probably not enough for mailgun to authenticate you. It should probably be `mail@mg.mydomain.com`

I’d guess you think `DISCOURSE_SMTP_DOMAIN` is the domain of the user? It’s not - it’s the EHLO domain. You almost definitely don’t need to set it.

---

<div class="post-metadata">

### Author: ![wal](https://avatars.discourse-cdn.com/v4/letter/w/d6d6ee/32.png) [@wal](https://meta.discourse.org/u/wal)
#### Post date: [July 23, 2024, 8:32pm UTC](https://meta.discourse.org/t/email-does-not-work-net-smtpauthenticationerror/317828/6 "2024-07-23T20:32:15Z")

</div>

> [@supermathie](#):
>
> I’d wager `DISCOURSE_SMTP_USER_NAME` is incorrect - `mail` is probably not enough for mailgun to authenticate you.

I just realized this as well, when I tested with `telnet` I used “[mail@mg.mydomain.com](mailto:mail@mg.mydomain.com)” as the username and it worked, so I will try it again with that as the `DISCOURSE_SMTP_USER_NAME`

> I’d guess you think `DISCOURSE_SMTP_DOMAIN` is the domain of the user? It’s not - it’s the EHLO domain. You probably don’t need to set it.

not sure I follow what this means

for MailGun I was using `mg.mydomain.com`, for Discourse I was using `discourse.mydomain.com`. I dont actually have any DNS records set at the moment for `mydomain.com`, only for the Discourse subdomain and the TXT records for the MailGun DNS

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [July 23, 2024, 8:34pm UTC](https://meta.discourse.org/t/email-does-not-work-net-smtpauthenticationerror/317828/7 "2024-07-23T20:34:09Z")

</div>

> [@wal](#):
>
> not sure I follow what this means

Remove the line for `DISCOURSE_SMTP_DOMAIN`, you almost definitely don’t need it.

It’s used during SMTP negotiation as the HELO/EHLO domain.

---

<div class="post-metadata">

### Author: ![wal](https://avatars.discourse-cdn.com/v4/letter/w/d6d6ee/32.png) [@wal](https://meta.discourse.org/u/wal)
#### Post date: [July 23, 2024, 8:34pm UTC](https://meta.discourse.org/t/email-does-not-work-net-smtpauthenticationerror/317828/8 "2024-07-23T20:34:16Z")

</div>

oh yeah also when I tested with telnet, I was indeed able to send the email from all of the following addresses

- `mail@discourse.mydomain.com`
- `mail@mydomain.com`
- `mail@mg.mydomain.com`

Not sure which one I am actually supposed to be using? Does it matter?

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [July 23, 2024, 8:36pm UTC](https://meta.discourse.org/t/email-does-not-work-net-smtpauthenticationerror/317828/9 "2024-07-23T20:36:45Z")

</div>

> [@wal](#):
>
> Not sure which one I am actually supposed to be using?

_That_ depends on your setup and what you want your mail flow to look like.

---

<div class="post-metadata">

### Author: ![wal](https://avatars.discourse-cdn.com/v4/letter/w/d6d6ee/32.png) [@wal](https://meta.discourse.org/u/wal)
#### Post date: [July 23, 2024, 8:45pm UTC](https://meta.discourse.org/t/email-does-not-work-net-smtpauthenticationerror/317828/10 "2024-07-23T20:45:14Z")

</div>

its working now, thanks all for the help 🙂

the solution was to use

```plaintext
  DISCOURSE_SMTP_USER_NAME: mail@mg.mydomain.com

```

instead of

```plaintext
  DISCOURSE_SMTP_USER_NAME: mail

```

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [August 22, 2024, 8:45pm UTC](https://meta.discourse.org/t/email-does-not-work-net-smtpauthenticationerror/317828/11 "2024-08-22T20:45:31Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
