Skip to content

Commit 18307bc

Browse files
committed
Mailtrap: add webhook tests and update test configs
1 parent b45a10a commit 18307bc

File tree

7 files changed

+384
-2
lines changed

7 files changed

+384
-2
lines changed

.github/workflows/integration-test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ jobs:
4444
- { tox: django41-py310-mailersend, python: "3.12" }
4545
- { tox: django41-py310-mailgun, python: "3.12" }
4646
- { tox: django41-py310-mailjet, python: "3.12" }
47+
- { tox: django41-py310-mailtrap, python: "3.12" }
4748
- { tox: django41-py310-mandrill, python: "3.12" }
4849
- { tox: django41-py310-postal, python: "3.12" }
4950
- { tox: django41-py310-postmark, python: "3.12" }

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Anymail currently supports these ESPs:
3131
* **MailerSend**
3232
* **Mailgun** (Sinch transactional email)
3333
* **Mailjet** (Sinch transactional email)
34+
* **Mailtrap**
3435
* **Mandrill** (MailChimp transactional email)
3536
* **Postal** (self-hosted ESP)
3637
* **Postmark** (ActiveCampaign transactional email)

anymail/backends/mailtrap.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ def __init__(
5858
"Api-Token": backend.api_token,
5959
"Content-Type": "application/json",
6060
"Accept": "application/json",
61+
"User-Agent": "django-anymail (https://github.com/anymail/django-anymail)",
6162
}
63+
# Yes, the parent sets this, but setting it here, too, gives type hints
6264
self.backend = backend
6365
self.metadata = None
6466
super().__init__(

anymail/webhooks/mailtrap.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ def parse_events(self, request):
5959
"click": EventType.CLICKED,
6060
"bounce": EventType.BOUNCED,
6161
"soft bounce": EventType.DEFERRED,
62-
"blocked": EventType.REJECTED,
6362
"spam": EventType.COMPLAINED,
6463
"unsubscribe": EventType.UNSUBSCRIBED,
6564
"reject": EventType.REJECTED,
@@ -73,6 +72,8 @@ def parse_events(self, request):
7372
"spam": RejectReason.SPAM,
7473
"unsubscribe": RejectReason.UNSUBSCRIBED,
7574
"reject": RejectReason.BLOCKED,
75+
"suspension": RejectReason.OTHER,
76+
"soft bounce": RejectReason.OTHER,
7677
}
7778

7879
def esp_to_anymail_event(self, esp_event: MailtrapEvent):
@@ -91,7 +92,7 @@ def esp_to_anymail_event(self, esp_event: MailtrapEvent):
9192
event_id=esp_event.get("event_id", None),
9293
recipient=esp_event.get("email", None),
9394
reject_reason=reject_reason,
94-
mta_response=esp_event.get("response_code", None),
95+
mta_response=esp_event.get("response", None),
9596
tags=tags,
9697
metadata=custom_variables,
9798
click_url=esp_event.get("url", None),

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ keywords = [
2626
"Brevo", "SendinBlue",
2727
"MailerSend",
2828
"Mailgun", "Mailjet", "Sinch",
29+
"Mailtrap",
2930
"Mandrill", "MailChimp",
3031
"Postal",
3132
"Postmark", "ActiveCampaign",

0 commit comments

Comments
 (0)