Question

Discourse: How to set up Discourse on subdomain but have SMPT /Email on main domain?

https://github.com/discourse/discourse/blob/master/docs/INSTALL-email.md

I have been following these directions on setting up Discourse, but I noticed that for setting up my email, I need to have the email on the same domain of the discourse instance which will be a subdomain, rather than the main domain of the site. Is there a way around this?


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

KFSys
Site Moderator
Site Moderator badge
July 24, 2023

Heya,

Yes, there is a way around this.

Discourse uses an email for a few different things:

  1. Sending emails from an address (like no-reply@discourse.example.com or no-reply@forum.example.com).
  2. Optionally, for receiving reply-by-email responses.

The first step is to set up an SMTP server that Discourse can use to send out emails. This server can be with any provider (like Mailgun, SendGrid, etc.), and it doesn’t need to be on the same domain as your Discourse instance. You’ll need to get the SMTP server details from your provider and then use these details to configure Discourse’s email settings.

When you’re setting up the SMTP server with your provider, you’ll typically need to verify ownership of the domain you’re sending from. This will involve adding some DNS records. For example, you might need to add an SPF record to your DNS to allow the SMTP server to send emails on behalf of your domain, and a DKIM record to allow for verification of the emails.

Here’s an example of what you might need to add to your DNS:

example.com. TXT "v=spf1 include:mailgun.org ~all"
mg._domainkey.example.com. TXT "k=rsa; p=MIGfM..."

These records allow Mailgun to send emails from your domain.

Then, in your Discourse settings, you’ll configure the SMTP server like this:

DISCOURSE_SMTP_ADDRESS: smtp.mailgun.org
DISCOURSE_SMTP_PORT: 587
DISCOURSE_SMTP_USER_NAME: postmaster@discourse.example.com
DISCOURSE_SMTP_PASSWORD: your-password

The DISCOURSE_SMTP_USER_NAME and DISCOURSE_SMTP_PASSWORD settings should be the credentials that your email provider (Mailgun, in this example) gave you.

Then, in your Discourse settings, set the notification email (the email that will be used as the “from” address for emails sent by Discourse) to something like no-reply@discourse.example.com.

As for receiving reply-by-email responses, this can be a bit trickier to set up, and it will depend on the capabilities of your email provider. You’ll need to create a catch-all email address (like replies@discourse.example.com) and then set up your email provider to forward all emails to this address to a specific Discourse endpoint.

Remember to always confirm the email setup by sending a test email from within Discourse. Also, bear in mind that the process can differ slightly depending on your email provider, but this should give you a general idea of what needs to be done.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel