This guide walks you through configuring SMTP email for a self-hosted Discourse forum running in Docker. You’ll edit the app.yml file, rebuild the container, and verify that emails send correctly. You’ll need root or sudo access to your server and the SMTP credentials from your email provider.
What You’ll Need
- A server running Discourse via Docker (installed using the official
discourse-setupscript or manually). - SMTP server hostname, port, username, and password (e.g., from your email host, transactional email service, or your own mail server).
- Access to the Discourse installation directory (usually
/var/discourse). - Ability to edit files with a text editor (e.g.,
nanoorvim). - A domain name that is properly configured for your Discourse instance (for DKIM/SPF if applicable).
Step-by-Step
- SSH into your server and navigate to the Discourse installation directory:
cd /var/discourse. - Open the app.yml file for editing:
sudo nano containers/app.yml. This file contains all the Docker configuration for your Discourse instance. - Find the SMTP section in the file. It looks like this (with placeholder values):
## SMTP settings smtp_address: smtp.example.com smtp_port: 587 smtp_user_name: yourusername smtp_password: yourpassword smtp_authentication: plain smtp_enable_starttls_auto: true smtp_openssl_verify_mode: noneIf the section doesn’t exist, add it under the
env:block. Theenv:block is where all environment variables for the container are defined. - Replace the placeholder values with your actual SMTP details:
smtp_address: Your SMTP server hostname (e.g.,smtp.gmail.comfor Gmail,smtp.mailgun.orgfor Mailgun).smtp_port: Usually587for TLS/STARTTLS,465for SSL, or25for plain (not recommended). Check with your provider.smtp_user_name: Your SMTP username (often the full email address).smtp_password: Your SMTP password or API key.smtp_authentication: Usuallyplainorlogin.smtp_enable_starttls_auto: Set totrueif your provider supports STARTTLS (most do).smtp_openssl_verify_mode: Leave asnoneunless you have a valid certificate chain issue; for production, consider setting topeerbut be aware of potential issues.
- Add the ‘From’ address (optional but recommended). In the same
env:block, add:DISCOURSE_SMTP_FROM_ADDRESS: 'noreply@yourdomain.com'This is the address that emails will appear to come from. It should be a real address that can receive replies if you want replies to work.
- Save the file and exit the editor.
- Rebuild the Discourse container to apply the changes. Run:
sudo ./launcher rebuild app. This will take a few minutes. It stops the container, applies the new configuration, and restarts it. - Verify the rebuild completed successfully. You should see no errors. If there are errors, check the logs with
sudo ./launcher logs app. - Test email sending from the Discourse admin panel. Go to
https://yourforum.com/admin/emailand click the “Send test email” button. Enter your email address and click send. - Check the email log if the test fails. In the same admin page, you can view the email logs to see any error messages returned by the SMTP server.
Common Mistakes
- Using the wrong port: Many providers block port 25. Use 587 or 465 as recommended.
- Forgetting to rebuild: Editing
app.ymlalone does nothing. You must rebuild the container. - Incorrect SMTP username: Some providers expect the full email address, others just the part before the @. Check your provider’s docs.
- Not enabling STARTTLS: If your provider requires it and you leave it off, emails will fail.
- Using a ‘From’ address that is not allowed: Some providers only allow sending from addresses you’ve verified. Use an address that matches your SMTP account.
- Copy-pasting spaces: Ensure there are no trailing spaces in the YAML values, as YAML is sensitive to indentation and whitespace.
Tips
- Use a dedicated transactional email service (like Mailgun, SendGrid, or Amazon SES) for better deliverability and to avoid being marked as spam.
- Set up SPF, DKIM, and DMARC records for your sending domain to improve email deliverability. Your SMTP provider will give you the exact records to add to your DNS.
- If you use Gmail or Google Workspace, you may need to generate an “App Password” if you have 2-factor authentication enabled.
- Test with a real email account you control, not just a fake address.
- Keep your SMTP password in a secure place; consider using environment variables or a secrets manager if you’re comfortable with that.
Troubleshooting
If emails are not sending, follow these steps:
- Check the email logs in the admin panel. Look for error messages like “connection refused”, “authentication failed”, or “timeout”.
- Test the SMTP connection manually from your server using
telnetoropenssl s_clientto see if the port is open and the server responds. - Verify your SMTP credentials by logging into your email provider’s web interface or using a tool like
swaksto send a test email directly. - Check the Discourse logs for any errors during the rebuild:
sudo ./launcher logs appand look for lines containing “smtp” or “mail”. - If you’re using a firewall, ensure that outbound connections to the SMTP port are allowed. Some cloud providers block port 25 by default.
- If you’re using a proxy or VPN, it might interfere with SMTP connections. Try disabling it temporarily.
- If all else fails, temporarily set
smtp_openssl_verify_mode: noneandsmtp_enable_starttls_auto: falseto see if it’s a TLS issue. If it works, then the problem is with certificate verification.
Frequently Asked Questions
- Do I need to rebuild the container every time I change SMTP settings? Yes, any changes to
app.ymlrequire a rebuild (sudo ./launcher rebuild app) to take effect. - Can I use the same SMTP server for multiple Discourse forums? Yes, as long as your SMTP provider allows it and you have separate credentials or use a catch-all address. Be aware of sending limits.
- What is the difference between port 587 and 465? Port 587 is for STARTTLS (the connection starts plain and then upgrades to TLS). Port 465 is for implicit SSL (the connection is TLS from the start). Use the one your provider specifies.
- Why are my emails going to spam? This is often due to missing SPF/DKIM records or a low sender reputation. Set up the DNS records and consider using a dedicated sending service.
- Can I use a Gmail account to send emails? Yes, but you’ll need to enable “Less secure app access” or use an App Password, and you’ll hit sending limits (500 per day for free accounts). It’s not recommended for production.
- How do I change the email subject prefix? That’s a separate setting in the Discourse admin panel under Settings > Basic Setup > “Email subject prefix”. It doesn’t require a rebuild.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Philips DST7060/20 7000 Series Iron: Specs & Fit
- Coal Fueled Jet Aircraft: Could It Work?675 L
- Remote Desktop on Raspberry Pi: How to Enable It
- Word Select Last Line in Paragraph?
- Google Assistant IFTTT Recipes: 7 Useful Automations
- OLED TVs in Dark Rooms: Why They Look Better and When They Don’t