How to add custom X-TAGS header to digest emails for external email analytics (Netcore)?

Hello everyone,

I’m a self-hosted Discourse user and I’m looking for a way to add a custom header, specifically X-TAGS, to our outgoing emails. The goal is to integrate with our email service provider (Netcore Email API) for better analytics and tracking. We want to be able to tag certain types of emails, like the weekly digest, for a more granular view of our email engagement.

Problem:

I need to add a header like X-TAGS: Digest to all the emails that are sent out as a digest. This header is for internal tracking and will be stripped by the email provider before delivery, so it won’t be visible to the end user.

What I’ve already explored:

  1. Site Settings: I’ve looked through the /admin/site_settings/category/email page and found the email custom headers setting. However, it seems to add a static header to all emails. I’m unsure if it’s possible to make this dynamic or to apply it only to a specific type of email (like the digest).
  2. Existing Forum Topics: I’ve searched the Discourse Meta forums and found some discussions about custom headers, but they mostly focus on adding topic tags to the email subject line or for user-side filtering (e.g., in Gmail), not for external email analytics. There doesn’t seem to be a straightforward, officially documented way to do this.

My questions are:

  1. Is there a built-in method or a specific site setting that I’m overlooking that would allow me to add a custom header like X-TAGS specifically to digest emails?
  2. If not, is this a feature that could be accomplished with a custom plugin?
  3. Would modifying the core code be the only solution, and if so, could you point me in the right direction (e.g., which files to look at)?

Any guidance or suggestions would be greatly appreciated. Thank you in advance for your help!

1 Like

No, this isn’t supported out of the box, aside from the email custom headers site setting which applies globally to all outgoing emails.

Yes, a custom plugin would the best approach here.

The current flow for digest emails, is as follows:

A plugin could hook into the message building process (Email::MessageBuilder) and inject(preferably via a modifier) your custom header conditionally, only for digests.

2 Likes