Troubleshooting email on a new Discourse install

You just installed Discourse via the install guide, but email doesn’t seem to work.

Unfortunately this means you can’t log in as an admin to finalize the install!

Let’s troubleshootize!

Did you enter email settings correctly?

Double check the settings in your containers/app.yml file; the simplest way is to run ./discourse-setup again. A valid email section looks like this:

DISCOURSE_DEVELOPER_EMAILS: 'name@example.com'
DISCOURSE_SMTP_ADDRESS: smtp.mailgun.org
DISCOURSE_SMTP_PORT: 587
DISCOURSE_SMTP_USER_NAME: postmaster@discourse.example.com
DISCOURSE_SMTP_PASSWORD: aUd34cdWKCu6CTjfoH7ykk

Double-check all values for correctness. Note that it all aligns, there are no leading # characters, and there are single quotes around the developer email field.

If you run ./discourse-doctor it will check several ways that your mail configuration might be broken.

If you had any errors in your app.yml and made changes , you MUST rebuild the container for those changes to take effect!

cd /var/discourse/
./launcher rebuild app

Are your SMTP connections being blocked?

To confirm that your server can indeed contact the email server, issue this command:

telnet smtp.mailgun.org 587

If you can’t connect this way, you’re almost certainly blocked. (And if you do get connected, the escape character for SMTP is ctrl+], then use quit to exit telnet.)

If this happens, contact your cloud provider support and confirm that your email connections are not being blocked.

What do the Discourse logs say?

From the command line, issue this command:

cd /var/discourse
tail shared/standalone/log/rails/production.log

This will show the last few lines of the log. Look for anything mail related. If you need to view the fuller logs, try

more shared/standalone/log/rails/production.log

To page through the complete log by pressing space. Look closely for any email related messages.

What do your email provider logs say?

Assuming there are no errors in the Discourse logs, or your Discourse mail configuration, the emails probably went out. The question, is what did your email provider do with them?

Most email providers have a log viewing function. Check the logs for your email domain and see what happened with the incoming emails.

Did you properly set up DKIM and SPF records for your domain?

You must enter those crucial DNS records for DKIM and SPF, otherwise your emails may arrive only sporadically, if at all.

Is the email domain correct?

The default email from address is based on the install domain plus subdomain, so if your URL is discourse.example.com it will be:

noreply@discourse.example.com

But if your mail provider is expecting:

noreply@example.com

… you may have problems! To get around this, edit and uncomment this line in app.yml

## If you want to set the 'From' email address for your first registration, uncomment and change:
#- exec: rails r "SiteSetting.notification_email='noreply@example.com'"
## After getting the first signup email, re-comment the line. It only needs to run once.

You’ll need to issue a rebuild after uncommenting the above line and setting the from email address as required.

You can also change this from the command line, if needed:

./launcher enter app
rails r "SiteSetting.notification_email = 'discourse@yoursite.com'"
exit

If you are using Mailgun, have you activated your domain and provided credit card information?

If you are using Mailgun, after you enter your DKIM and SPF records, you must visit https://mailgun.com/app/domains/YOUR.DISCOURSE.DOMAIN.com and click the “Check DNS Records Now” button. At the top of that page you should see “State ACTIVE” (in a calming green). If it says “State Unverified” (in a scary warning-yellow) Mailgun will not accept mail.

Mailgun now requires a credit card in order to deliver mail (other than to you). If your mailgun logs have a message about “free accounts,” this is your problem.

Other mail services have similar requirements.

Are you using an IP address as the mail domain?

This does not work in our experience. You must use a domain name when sending email, not an IP address like 192.168.1.1.

Need to log in without receiving a registration email?

We don’t recommend this, because your email is still broken, and you have a broken Discourse until email is working. But if you absolutely must log in as admin with email broken, here’s what to do:

cd /var/discourse
./launcher enter app
rake admin:create

And answer the prompts. It takes a few seconds before they appear. When it asks for the password, you will not be able to see what you type. That is why it makes you type it twice.

Email smtp port selection

The ability to be able to AUTH using ‘telnet’ is extremely important in your first steps of email troubleshooting. You may need to try alternate ports such as port 2525 or port 587 when things do not seem to work as expected.

Command Line SMTP tests for experienced sysadmins

If you’re comfortable with the command line, these might help diagnose network or certificate problems. If these do not seem “easy-to-follow” then you should please ignore this section.

See also How to test SMTP Authentication and StartTLS - Sysadmins of the North.

Office 365 Tweaks

If you’re using Office 365, be sure to include these (the first line is what you are likely missing):

DISCOURSE_SMTP_AUTHENTICATION: login
DISCOURSE_SMTP_ENABLE_START_TLS: true
DISCOURSE_SMTP_PORT: 587

and set the correct notification_email (which is likely different from your forum hostname).

Email still doesn’t work! What next?

Anything else I forgot here? Feel free to edit this.

39 Likes

Hi, everybody. after changing the data wuth ./discourse-setup, i get the following error


Please help me solve this problem
The command . / launcher rebuild app causes the same error

1 Like

can’t receive emails after installing

1 Like

Your error message points you to the problem @Mikhail_Tyuftyaev

Screen Shot 2020-12-19 at 4.40.21 PM

“Follow the yellow-brick road” when it comes to error messages :slight_smile:

"Follow the yellow-brick road, follow the yellow-brick road, follow, follow, follow, follow, follow the yellow-brick road… "

1 Like

Did you do what the error message said? I always just search for errors on the internet when I don’t understand them. I don’t understand yours but here’s where I ended up: https://yamlchecker.com/ There are likely command line equivalents.

1 Like

Could you set out what you did, what you expected to happen, and what happened instead?

1 Like

Hi. I don’t know if I’m an idiot, but I tried to install Discourse using a VM with Googles cloud service. I never got the ports working, so I eventually gave up. Then I found out that you could install it through Google’s “Marketplace”.

The Marketplace install installs Discourse by “one-click” installation. On Debian. And I connected it to a subdomain at my host, and everything works fine!
BUT.
WHERE DO I SET THE MAIL.

I mean, I can SSH into my VM instance at Google, but I cannot find anything like “launcher” or “app.yml”. Tried to search through the whole tree, recursively by using command “find . -name “app.yml””, and came up with nothing. Manually traversed it all - nothing.

Any idea on how I can set up my SMTP? I need it to email access to some more people helping me to try out the forum. Thanks in advance.

1 Like

You’ll need to ask Google since it’s their method. A guess is that your set the same environment variables that are in app.yml… However it is that you do that.

1 Like

After an installation on a Plesk server running Ubuntu 18.04, I am getting this after running discourse-doctor:

SMTP server connection successful.
Sending to name@example.com. . .
Sending mail failed.
Replacing: SMTP_PASSWORD
Replacing: LETSENCRYPT_ACCOUNT_EMAIL
Replacing: DEVELOPER_EMAILS
Replacing: DISCOURSE_DB_PASSWORD
Replacing: Sending mail to

The same settings work in Thunderbird. Any ideas what the Problem might be?

1 Like