# Hooks for customization of digest and notification emails

**URL:** https://meta.discourse.org/t/hooks-for-customization-of-digest-and-notification-emails/164394
**Category:** Feature
**Created:** [September 17, 2020, 10:13pm UTC](https://meta.discourse.org/t/hooks-for-customization-of-digest-and-notification-emails/164394 "2020-09-17T22:13:46Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [September 17, 2020, 10:13pm UTC](https://meta.discourse.org/t/hooks-for-customization-of-digest-and-notification-emails/164394/1 "2020-09-17T22:13:46Z")

</div>

I have a client who would like to include ads in summary and notification emails. I’ve “crafted” a [plugin](https://github.com/pfaffman/discourse-add-to-summary) that allows adding some text to the digest email (which I think needs some updating to catch up with changes made to that template).

I don’t like that I have to override the entire template to customize those emails.

Would it be possible to include a way to add to those emails without overriding the template?

The plugin works by having taking a topic ID in a custom field and including `raw` of the last post in the topic as the text added to the email (just before or after the header). Though I think it’s a pretty clever hack, that seems a bit too fiddly a solution to suggest adding to core. Perhaps there’s a way to have the Ad plugin be able to apply house ads to the digest and summary emails?

### Managing a fragile plugin

Maybe I should write a spec that compares the digest email with the plugin off with the digest email with the plugin on but not configured to add anything to the email? Then I’d catch changes to the core template?

---

<div class="post-metadata">

### Author: ![jrgong](https://avatars.discourse-cdn.com/v4/letter/j/c57346/32.png) [@jrgong](https://meta.discourse.org/u/jrgong)
#### Post date: [August 18, 2023, 11:45am UTC](https://meta.discourse.org/t/hooks-for-customization-of-digest-and-notification-emails/164394/2 "2023-08-18T11:45:45Z")

</div>

Hey Jay

Does this plugin “work” with Discourse 3.1? Or at least worth a test?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [August 18, 2023, 12:00pm UTC](https://meta.discourse.org/t/hooks-for-customization-of-digest-and-notification-emails/164394/3 "2023-08-18T12:00:49Z")

</div>

You can give it a shot. I don’t think I’ve heard from them since this message, so I’m guessing they have not upgraded since then.

You can let me know if it’s broken. I likely won’t have time to fix it for free, but I might.

---

<div class="post-metadata">

### Author: ![thoka](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thoka/32/115652_2.png) [@thoka](https://meta.discourse.org/u/thoka)
#### Post date: [February 15, 2025, 7:33am UTC](https://meta.discourse.org/t/hooks-for-customization-of-digest-and-notification-emails/164394/4 "2025-02-15T07:33:39Z")

</div>

As I understand, `digest_custom_html` and `digest_custom_text` already implement hooks for [`digest.html.erb`](https://github.com/discourse/discourse/blob/main/app/views/user_notifications/digest.html.erb) and [`digest.text.erb`](https://github.com/discourse/discourse/blob/main/app/views/user_notifications/digest.text.erb). So a basic implementation of this request would involve adding more of these hooks?

A more advanced implementation could provide sub-templates, which could be used to supply plugin authors with styling and formatting code maintained by Discourse.

Do I understand correctly that your implementation would be possible with one `digest_custom_html("before_preheader")` added to [`digest.html.erb`](https://github.com/discourse/discourse/blob/main/app/views/user_notifications/digest.html.erb)?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [February 15, 2025, 10:57am UTC](https://meta.discourse.org/t/hooks-for-customization-of-digest-and-notification-emails/164394/5 "2025-02-15T10:57:34Z")

</div>

I think so. I haven’t looked closely at how it works in years.

---

<div class="post-metadata">

### Author: ![jrgong](https://avatars.discourse-cdn.com/v4/letter/j/c57346/32.png) [@jrgong](https://meta.discourse.org/u/jrgong)
#### Post date: [May 11, 2025, 6:34pm UTC](https://meta.discourse.org/t/hooks-for-customization-of-digest-and-notification-emails/164394/6 "2025-05-11T18:34:06Z")

</div>

Hey @thoka did you manage to implementent anything via those hooks? We are currently looking to inject some simple sponsored segments via those hooks

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [May 11, 2025, 6:51pm UTC](https://meta.discourse.org/t/hooks-for-customization-of-digest-and-notification-emails/164394/7 "2025-05-11T18:51:13Z")

</div>

I did that. As long as you generate your injections with html\_safe you’re in good shape.

There is discussion at [Fixing digest\_custom\_html to be treated as HTML (was: Overriding digest.html.erb)](https://meta.discourse.org/t/fixing-digest-custom-html-to-be-treated-as-html-was-overriding-digest-html-erb/361988)
