Setting up the mail-receiver direct-delivery Discourse incoming mail system

Some notes I made following setting up the mail-receiver container, using the instructions below

These instructions are written in a weird way. They are ‘sort-of’ clear, until you try to follow them and then you realise there’s lots of little uncertainties left!

API Keys

  • The tutorial on Meta didn’t say what kind of API key you need. I used an ‘all-users’ one and it worked fine. I guess the mail-receiver needs to be able to post as potentially any user that might reply via email

Placeholder templates for containers/mail_receiver.yml

  • Unless you have a weird setup, the mail_receiver container and the app (Discourse) container are on the same machine, at the same subdomain and domain. So if you put in that domain here, the placeholders below will give you copy and pastable text. This placeholder assumes you are using HTTPS like a good boy/girl.


MAIL_DOMAIN==DOMAIN=
DISCOURSE_MAIL_ENDPOINT=https://=DOMAIN=/admin/email/handle_mail

Firewalls on servers

  • Check you have port 25 open in your firewall (unless you used a different port) - I had been into my server management platform and changed the firewall but the settings didn’t save the first time, this was discovered when going back to check.

HTTPS/HTTP for the Discourse API endpoint

  • Check that DISCOURSE_MAIL_ENDPOINT is correct including http/https scheme, depending what you are using. The placeholder in mail-receiver.yml uses http, and then I was thinking ‘maybe it doesn’t need HTTPS because they are on the same box and it’s a local connection’, etc, etc. Suffice to say, if you are using HTTPS only on your Discourse instance, it doesn’t connect unless you also use HTTPS here.

  • It would have been all that much clearer if they had called this DISCOURSE_API_ENDPOINT, because that’s what it is. The normal Discourse API. It’s got nothing to do with mail specifically. The mail-receiver is the bit handling mail.

Debugging

do all these from your development machine NOT the server we are trying to connect to!

  • check you can resolve the MX record
    dig +short MX =DOMAIN=

  • check you can connect to the server on port 25
    nc -zvw3 =DOMAIN= 25 (command explanation here)

  • then try telnet
    telnet =DOMAIN= 25 (explanation and next steps here)

  • then go onto the Discourse server to look in the mail-receiver logs and see that something is coming through.
    ./launcher logs mail-receiver

  • then look at the Discourse logs via the web interface at https://=DOMAIN=/logs

1 Like