forked from GithubBackups/healthchecks
Add "List-Unsubscribe" header to alert and report emails
This commit is contained in:
parent
c4543bce58
commit
b9a81ad382
@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
|
||||
|
||||
### Improvements
|
||||
- Load settings from environment variables
|
||||
- Add "List-Unsubscribe" header to alert and report emails
|
||||
|
||||
|
||||
## 1.2.0 - 2018-10-20
|
||||
|
@ -150,18 +150,21 @@ class Profile(models.Model):
|
||||
# rendering the template
|
||||
checks = list(checks)
|
||||
|
||||
unsub_url = self.reports_unsub_url()
|
||||
|
||||
headers = {"List-Unsubscribe": unsub_url}
|
||||
ctx = {
|
||||
"checks": checks,
|
||||
"sort": self.sort,
|
||||
"now": timezone.now(),
|
||||
"unsub_link": self.reports_unsub_url(),
|
||||
"unsub_link": unsub_url,
|
||||
"notifications_url": self.notifications_url(),
|
||||
"nag": nag,
|
||||
"nag_period": self.nag_period.total_seconds(),
|
||||
"num_down": num_down
|
||||
}
|
||||
|
||||
emails.report(self.user.email, ctx)
|
||||
emails.report(self.user.email, ctx, headers)
|
||||
return True
|
||||
|
||||
def can_invite(self):
|
||||
|
@ -246,6 +246,7 @@ class NotifyTestCase(BaseTestCase):
|
||||
|
||||
email = mail.outbox[0]
|
||||
self.assertTrue("X-Bounce-Url" in email.extra_headers)
|
||||
self.assertTrue("List-Unsubscribe" in email.extra_headers)
|
||||
|
||||
def test_it_skips_unverified_email(self):
|
||||
self._setup_data("email", "alice@example.org", email_verified=False)
|
||||
|
@ -40,6 +40,9 @@ class SendAlertsTestCase(BaseTestCase):
|
||||
self.assertTrue(self.profile.next_report_date > now())
|
||||
self.assertEqual(len(mail.outbox), 1)
|
||||
|
||||
email = mail.outbox[0]
|
||||
self.assertTrue("List-Unsubscribe" in email.extra_headers)
|
||||
|
||||
def test_it_obeys_next_report_date(self):
|
||||
self.profile.next_report_date = now() + td(days=1)
|
||||
self.profile.save()
|
||||
|
@ -50,7 +50,12 @@ class Email(Transport):
|
||||
if not self.channel.email_verified:
|
||||
return "Email not verified"
|
||||
|
||||
headers = {"X-Bounce-Url": bounce_url}
|
||||
unsub_link = self.channel.get_unsub_link()
|
||||
|
||||
headers = {
|
||||
"X-Bounce-Url": bounce_url,
|
||||
"List-Unsubscribe": unsub_link
|
||||
}
|
||||
|
||||
try:
|
||||
# Look up the sorting preference for this email address
|
||||
@ -67,7 +72,7 @@ class Email(Transport):
|
||||
"checks": list(self.checks()),
|
||||
"sort": sort,
|
||||
"now": timezone.now(),
|
||||
"unsub_link": self.channel.get_unsub_link()
|
||||
"unsub_link": unsub_link
|
||||
}
|
||||
|
||||
emails.alert(self.channel.value, ctx, headers)
|
||||
|
@ -56,8 +56,8 @@ def verify_email(to, ctx):
|
||||
send("verify-email", to, ctx)
|
||||
|
||||
|
||||
def report(to, ctx):
|
||||
send("report", to, ctx)
|
||||
def report(to, ctx, headers={}):
|
||||
send("report", to, ctx, headers)
|
||||
|
||||
|
||||
def invoice(to, ctx, filename, pdf_data):
|
||||
|
@ -18,18 +18,6 @@ Here is a summary of your checks:
|
||||
Thanks,<br>
|
||||
The {% escaped_site_name %} Team
|
||||
|
||||
<script type="application/ld+json">
|
||||
{
|
||||
"@context": "http://schema.org",
|
||||
"@type": "EmailMessage",
|
||||
"potentialAction": {
|
||||
"@type": "ViewAction",
|
||||
"url": "{{ check.details_url }}",
|
||||
"name": "View in {% site_name%}"
|
||||
},
|
||||
"description": "View in {% site_name%}"
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
{% block unsub %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user