Email does not work; Net::SMTPAuthenticationError

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

I can enter telnet on the host and send email manually without issue (smtp - Easiest way to send a test email from a server, to test settings? - Server Fault)

The app.yml has these contents

  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

======================================== 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?

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

2 Likes

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.

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.

1 Like

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.

1 Like

I just realized this as well, when I tested with telnet I used “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

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.

1 Like

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?

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

1 Like

its working now, thanks all for the help :slight_smile:

the solution was to use

  DISCOURSE_SMTP_USER_NAME: mail@mg.mydomain.com

instead of

  DISCOURSE_SMTP_USER_NAME: mail
2 Likes

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