I think I solved the Bad CSRF issue by adding user and api key to the URL but now I am seeing and error in the logs: admin/email_controller.rb error at line 86, missing required parameter "email’.
Can I assume this is a json parameter that mailgun is not populating because of wrong API or something?
I don’t believe Mailgun’s mail forwarding will work as-is with Discourse. It doesn’t pass the email data in the right way and there doesn’t appear to be a way to change that on either end Mailgun nor Discourse.
The detail
Within Mailgun’s documentation there is a Django code example which indicates what is passed to the HTTP endpoint by mailguns forward functionality.
An example payload at the bottom of this page confirms this.
For reference here is the code sample:
Consider this Django code:
# Handler for HTTP POST to http://myhost.com/messages for the route defined above
def on_incoming_message(request):
if request.method == 'POST':
sender = request.POST.get('sender')
recipient = request.POST.get('recipient')
subject = request.POST.get('subject', '')
body_plain = request.POST.get('body-plain', '')
body_without_quotes = request.POST.get('stripped-text', '')
# note: other MIME headers are also posted here...
# attachments:
for key in request.FILES:
file = request.FILES[key]
# do something with the file
# Returned text is ignored but HTTP status code matters:
# Mailgun wants to see 2xx, otherwise it will make another attempt in 5 minutes
return HttpResponse('OK')
Note that this means that many POST parameters including sender, recipient, subject, body-plain, stripped-text and files as separate “chunks”.
This is not what Discourse expects to be sent to the /admin/email/handle_mail endpoint - it simply wants the complete raw email as the email parameter.
I followed these directions exactly, and am getting the following error at mailgun. Should I assume that I need to migrate away from mailgun to receive reply emails?
Also, I’m confused what the mailgun api key is used for. Says it’s used to verify webhook messages. Can someone elaborate?
I’m reviewing my other setting to make sure I have not missed anything:
manual polling enabled = True
mailgun api key = Provided
reply by email enabled = True
reply by email address = replies+%{reply_key}@example.com
at mailgun - Forward to: http://example.com/admin/email/handle_mail
Please re-read the instructions linked as they have nothing to do with mailgun - mailgun will not be used for receiving mail when following those instructions correctly.
Sorry - I see. Pure stupidity on my part. Thx for pointing me in the right direction. Inbound email gets delivered and processed by your own server and as you mentioned, does not hit mailgun. Need to open port 25 on EC2 instance.
I’m using mailgun to forward discourse+%{reply_key}@literatecomputing.com to a gmail inbox that is retrieved via pop3 and I believe that it’s working just fine.
That’s not directly to Discourse via the HTTP POST API which is what this topic was about…
GMail is acting as a middle man and this delays the processing of emails into Discourse by 1 to 2 times the POP3 polling time.
There are a few other POP3/Gmail issues which use of the direct mechanism resolves.
One thing you don’t get is Gmail’s superb SPAM processing. However there is already a decent level of protection both in the mail handler and Discourse especially if Akismet is installed.