Webhook for Mandrill inbound email notifications, WIP

This commit is contained in:
Pēteris Caune 2015-08-01 16:06:04 +03:00
parent b75ab00d18
commit 32fb29c299
2 changed files with 13 additions and 3 deletions

View File

@ -15,7 +15,10 @@ class EmailTestCase(TestCase):
"event": "inbound",
"msg": {
"raw_msg": "This is raw message",
"to": ["somewhere@example.com", "%s@example.com" % check.code]
"to": [
["somewhere@example.com", "Somebody"],
["%s@example.com" % check.code, "Healthchecks"]
]
}
}]
@ -29,3 +32,7 @@ class EmailTestCase(TestCase):
pings = list(Ping.objects.all())
assert pings[0].scheme == "email"
assert pings[0].body == "This is raw message"
def test_it_rejects_get(self):
r = self.client.get("/handle_email/")
assert r.status_code == 400

View File

@ -40,10 +40,13 @@ def ping(request, code):
@csrf_exempt
def handle_email(request):
if request.method != "POST":
return HttpResponseBadRequest()
events = json.loads(request.POST["mandrill_events"])
for event in events:
for to_address in event["msg"]["to"]:
code, domain = to_address.split("@")
for recipient_address, recipient_name in event["msg"]["to"]:
code, domain = recipient_address.split("@")
try:
check = Check.objects.get(code=code)
except ValueError: