Skip to content

Commit

Permalink
Mailtrap: add webhook tests and update test configs
Browse files Browse the repository at this point in the history
  • Loading branch information
cahna committed Nov 17, 2024
1 parent b45a10a commit c2a7387
Show file tree
Hide file tree
Showing 7 changed files with 362 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
- { tox: django41-py310-mailersend, python: "3.12" }
- { tox: django41-py310-mailgun, python: "3.12" }
- { tox: django41-py310-mailjet, python: "3.12" }
- { tox: django41-py310-mailtrap, python: "3.12" }
- { tox: django41-py310-mandrill, python: "3.12" }
- { tox: django41-py310-postal, python: "3.12" }
- { tox: django41-py310-postmark, python: "3.12" }
Expand Down
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Anymail currently supports these ESPs:
* **MailerSend**
* **Mailgun** (Sinch transactional email)
* **Mailjet** (Sinch transactional email)
* **Mailtrap**
* **Mandrill** (MailChimp transactional email)
* **Postal** (self-hosted ESP)
* **Postmark** (ActiveCampaign transactional email)
Expand Down
2 changes: 2 additions & 0 deletions anymail/backends/mailtrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ def __init__(
"Api-Token": backend.api_token,
"Content-Type": "application/json",
"Accept": "application/json",
"User-Agent": "django-anymail (https://github.com/anymail/django-anymail)",
}
# Yes, the parent sets this, but setting it here, too, gives type hints
self.backend = backend
self.metadata = None
super().__init__(
Expand Down
5 changes: 3 additions & 2 deletions anymail/webhooks/mailtrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def parse_events(self, request):
"click": EventType.CLICKED,
"bounce": EventType.BOUNCED,
"soft bounce": EventType.DEFERRED,
"blocked": EventType.REJECTED,
"spam": EventType.COMPLAINED,
"unsubscribe": EventType.UNSUBSCRIBED,
"reject": EventType.REJECTED,
Expand All @@ -73,6 +72,8 @@ def parse_events(self, request):
"spam": RejectReason.SPAM,
"unsubscribe": RejectReason.UNSUBSCRIBED,
"reject": RejectReason.BLOCKED,
"suspension": RejectReason.OTHER,
"soft bounce": RejectReason.OTHER,
}

def esp_to_anymail_event(self, esp_event: MailtrapEvent):
Expand All @@ -91,7 +92,7 @@ def esp_to_anymail_event(self, esp_event: MailtrapEvent):
event_id=esp_event.get("event_id", None),
recipient=esp_event.get("email", None),
reject_reason=reject_reason,
mta_response=esp_event.get("response_code", None),
mta_response=esp_event.get("response", None),
tags=tags,
metadata=custom_variables,
click_url=esp_event.get("url", None),
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ keywords = [
"Brevo", "SendinBlue",
"MailerSend",
"Mailgun", "Mailjet", "Sinch",
"Mailtrap",
"Mandrill", "MailChimp",
"Postal",
"Postmark", "ActiveCampaign",
Expand Down
Loading

0 comments on commit c2a7387

Please sign in to comment.