lalejand asks whether the Table of Contents (TOC) generated by the DiscoTOC theme component can be included in email notifications for newsletter posts. NateDhaliwal clarifies that theme components only affect the front-end (browser) and cannot modify the back-end email content.
Moin suggests a manual workaround: since the TOC must be part of the post body to appear in emails, users can use a bookmarklet to generate the TOC, paste it into the post, and then either remove it after sending or hide it from the forum view using another theme component. The proposed workflow involves publishing the topic, generating the TOC via the bookmarklet, editing the post to include it, and subsequently managing its visibility.
NateDhaliwal adds that while some email clients support basic HTML/CSS, JavaScript is generally unavailable in emails, making dynamic generation within the email itself impractical. He raises the possibility of a plugin that intercepts emails to add a static TOC before sending, though questions if this is technically feasible.
The category where I publish the newsletter in is configured so that every member of the forum will receive the post by email. But in the email the TOC is not present.
Would it be possible to insert the TOC also in the email sent? If yes, how?
Theme components only change the front end of Discourse (what you see in the browser); they do not change the backend which sends the email.
So the TOC in the email would have to be part of the post. You could include a section at the top. A few years ago a bookmarklet was shared that uses the headings in the post to generate that, so you can paste it into the post: I created a bookmarklet to create the table of content for forum posts.
You could hide that with a theme component or remove it after the emails have been sent to avoid users on the forum seeing both.
So you would
publish the topic,
use the bookmarklet to generate a TOC,
edit the post to add it
remove the TOC after the emails were sent (or use a component to hide the TOC in the forum)
Some email clients support some HTML and CSS, but JS is not really available AFAIK. But maybe a plugin to intercept emails, add a simple TOC at the start and send? Is that even possible though?