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
|
### Improvements
|
||||||
- Load settings from environment variables
|
- Load settings from environment variables
|
||||||
|
- Add "List-Unsubscribe" header to alert and report emails
|
||||||
|
|
||||||
|
|
||||||
## 1.2.0 - 2018-10-20
|
## 1.2.0 - 2018-10-20
|
||||||
|
@ -150,18 +150,21 @@ class Profile(models.Model):
|
|||||||
# rendering the template
|
# rendering the template
|
||||||
checks = list(checks)
|
checks = list(checks)
|
||||||
|
|
||||||
|
unsub_url = self.reports_unsub_url()
|
||||||
|
|
||||||
|
headers = {"List-Unsubscribe": unsub_url}
|
||||||
ctx = {
|
ctx = {
|
||||||
"checks": checks,
|
"checks": checks,
|
||||||
"sort": self.sort,
|
"sort": self.sort,
|
||||||
"now": timezone.now(),
|
"now": timezone.now(),
|
||||||
"unsub_link": self.reports_unsub_url(),
|
"unsub_link": unsub_url,
|
||||||
"notifications_url": self.notifications_url(),
|
"notifications_url": self.notifications_url(),
|
||||||
"nag": nag,
|
"nag": nag,
|
||||||
"nag_period": self.nag_period.total_seconds(),
|
"nag_period": self.nag_period.total_seconds(),
|
||||||
"num_down": num_down
|
"num_down": num_down
|
||||||
}
|
}
|
||||||
|
|
||||||
emails.report(self.user.email, ctx)
|
emails.report(self.user.email, ctx, headers)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def can_invite(self):
|
def can_invite(self):
|
||||||
|
@ -246,6 +246,7 @@ class NotifyTestCase(BaseTestCase):
|
|||||||
|
|
||||||
email = mail.outbox[0]
|
email = mail.outbox[0]
|
||||||
self.assertTrue("X-Bounce-Url" in email.extra_headers)
|
self.assertTrue("X-Bounce-Url" in email.extra_headers)
|
||||||
|
self.assertTrue("List-Unsubscribe" in email.extra_headers)
|
||||||
|
|
||||||
def test_it_skips_unverified_email(self):
|
def test_it_skips_unverified_email(self):
|
||||||
self._setup_data("email", "alice@example.org", email_verified=False)
|
self._setup_data("email", "alice@example.org", email_verified=False)
|
||||||
|
@ -30,7 +30,7 @@ class SendAlertsTestCase(BaseTestCase):
|
|||||||
|
|
||||||
def test_it_sends_report(self):
|
def test_it_sends_report(self):
|
||||||
cmd = Command()
|
cmd = Command()
|
||||||
cmd.stdout = Mock() # silence output to stdout
|
cmd.stdout = Mock() # silence output to stdout
|
||||||
cmd.pause = Mock() # don't pause for 1s
|
cmd.pause = Mock() # don't pause for 1s
|
||||||
|
|
||||||
found = cmd.handle_one_monthly_report()
|
found = cmd.handle_one_monthly_report()
|
||||||
@ -40,6 +40,9 @@ class SendAlertsTestCase(BaseTestCase):
|
|||||||
self.assertTrue(self.profile.next_report_date > now())
|
self.assertTrue(self.profile.next_report_date > now())
|
||||||
self.assertEqual(len(mail.outbox), 1)
|
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):
|
def test_it_obeys_next_report_date(self):
|
||||||
self.profile.next_report_date = now() + td(days=1)
|
self.profile.next_report_date = now() + td(days=1)
|
||||||
self.profile.save()
|
self.profile.save()
|
||||||
|
@ -50,7 +50,12 @@ class Email(Transport):
|
|||||||
if not self.channel.email_verified:
|
if not self.channel.email_verified:
|
||||||
return "Email not 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:
|
try:
|
||||||
# Look up the sorting preference for this email address
|
# Look up the sorting preference for this email address
|
||||||
@ -67,7 +72,7 @@ class Email(Transport):
|
|||||||
"checks": list(self.checks()),
|
"checks": list(self.checks()),
|
||||||
"sort": sort,
|
"sort": sort,
|
||||||
"now": timezone.now(),
|
"now": timezone.now(),
|
||||||
"unsub_link": self.channel.get_unsub_link()
|
"unsub_link": unsub_link
|
||||||
}
|
}
|
||||||
|
|
||||||
emails.alert(self.channel.value, ctx, headers)
|
emails.alert(self.channel.value, ctx, headers)
|
||||||
|
@ -56,8 +56,8 @@ def verify_email(to, ctx):
|
|||||||
send("verify-email", to, ctx)
|
send("verify-email", to, ctx)
|
||||||
|
|
||||||
|
|
||||||
def report(to, ctx):
|
def report(to, ctx, headers={}):
|
||||||
send("report", to, ctx)
|
send("report", to, ctx, headers)
|
||||||
|
|
||||||
|
|
||||||
def invoice(to, ctx, filename, pdf_data):
|
def invoice(to, ctx, filename, pdf_data):
|
||||||
|
@ -18,18 +18,6 @@ Here is a summary of your checks:
|
|||||||
Thanks,<br>
|
Thanks,<br>
|
||||||
The {% escaped_site_name %} Team
|
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 %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block unsub %}
|
{% block unsub %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user