Skip to content

Instantly share code, notes, and snippets.



Created Jan 29, 2015
What would you like to do?
import logging
from django.http import HttpResponse
from django.views.decorators.cache import never_cache
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_http_methods
from email_reply_parser import EmailReplyParser
from email.utils import parseaddr
from import process_inbound_email
from import email_to_group_id
def process_inbound_message(request):
to_email = parseaddr(request.POST['To'])[1]
from_email = parseaddr(request.POST['From'])[1]
group_id = email_to_group_id(to_email)
except Exception:'%r is not a valid email address', to_email)
return HttpResponse(status=500)
payload = EmailReplyParser.parse_reply(request.POST['body-plain']).strip()
if not payload:
# If there's no body, we don't need to go any further
return HttpResponse(status=200)
process_inbound_email.delay(from_email, group_id, payload)
return HttpResponse(status=201)
import mock
from sentry.testutils import TestCase
from import group_id_to_email
body_plain = "foo bar"
class TestProcessInboundMessage(TestCase):
urls = ''
def setUp(self):
super(TestProcessInboundMessage, self).setUp()
self.event = self.create_event(event_id='a' * 32)
self.mailto = group_id_to_email(
def test_simple(self, process_inbound_email):
resp ='/api/0/mailgun/inbound/', {
'To': 'Sentry <%s>' % (self.mailto,),
'From': 'David <%s>' % (,),
'body-plain': body_plain,
assert resp.status_code == 201
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.