Opened 19 years ago
Last modified 15 months ago
#2625 new enhancement
Add option to send HTML mail messages
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | normal | Milestone: | next-major-releases |
Component: | notification | Version: | 0.11-stable |
Severity: | normal | Keywords: | notification email |
Cc: | mail@…, ander.tenno@…, broohaha@…, s.mitchell@…, lewis.francis@…, c00i90wn@…, m@…, benjamin.azan@…, diego.gentoo@…, daniel.oconnor@…, nicolas@…, jetcat@…, dbytesguard-trackhacks@…, ericacm@…, alejandro.popov@…, christophe.prevost@…, isaacsutherland@…, bill@…, macke@…, michael.illing@…, ethan.jucovy@…, dave@…, leho@…, charles_ymt@…, nielsen@…, Jun Omae, josh@…, lee@… | Branch: | |
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description
It would be nice if Trac was able to send notification emails in some sort of rich format, for example HTML. This way one would not have to use fixed fonts in the mail client.
Attachments (0)
Change History (75)
comment:1 by , 19 years ago
Keywords: | notification email added |
---|
comment:2 by , 19 years ago
comment:3 by , 19 years ago
I agree that ideally the email would look something like the ticket page. This is especially usefull for my case where we have non software developers fill in tickets. They always complain that the get some funny looking emails. I use Thunderbird and the mails look ok but when I use Outlook the get all distorted. Sending in HTML will solve this setting related issue, sending it looking like the ticket page is the icing on the cake.
comment:4 by , 19 years ago
peter: have you tried the latest trunk [2799]+ to check if it improves the ticket rendering in Outlook (have a look at the TracNotification page for the options).
comment:5 by , 19 years ago
Add my vote to the people who would like to see notification emails in rich text format. Any plans for this?
comment:6 by , 19 years ago
Cc: | added |
---|
comment:7 by , 19 years ago
Cc: | added |
---|
I'm not too worried about html format, but we're now forced to use Outlook 2003 at work, and it wraps the e-mail message very early (i.e. the lines of '-' above and below the summary are wrapped from about ¾ of the way along which looks fairly message.
Is there another way to stop outlook wrapping like this? That way I'd be quite happy with the plain test messages.
Cheers
Russell
comment:8 by , 19 years ago
Text messages start to be a problem when Wiki is used. Then you do get very funny looking emails.
comment:9 by , 19 years ago
Cc: | added |
---|
comment:10 by , 19 years ago
Cc: | added |
---|
comment:11 by , 19 years ago
Cc: | added |
---|
Add my voice to the chorus — requiring my users to force a monospace font is not going to go over very well.
comment:12 by , 19 years ago
Add another vote. Plus an option to send attachments in the notification e-mail when they are added to the ticket (should I file another ticket for that?)
comment:13 by , 19 years ago
Cc: | added |
---|
comment:14 by , 19 years ago
Cc: | added |
---|
Definately interested in this one (got here by searching for the option)
I use it alot to send C++ code snippets around, and it looks just unreadable in email.
comment:15 by , 18 years ago
Cc: | added |
---|
comment:18 by , 18 years ago
Component: | general → notification |
---|---|
Milestone: | → 0.12 |
Owner: | changed from | to
+ this should also be a user preference.
comment:20 by , 18 years ago
Replying to diego.gentoo@gmail.com:
Any news?
Since yesterday and the discussion you initiated? http://groups.google.com/group/trac-users/browse_thread/thread/50b20a8fdc262769
follow-up: 22 comment:21 by , 17 years ago
+ 10 more votes from me and my team. I didn't use trac for a long time because of silly unprofessional things like this (and the insistance on SQLite and the installation hastles of the templating engine). It's getting better and better but just needs a bit of polishing around the edges. Trac already has the processing engine to convert wiki markup to HTML, why not just reuse that in generating notification emails?
comment:22 by , 17 years ago
Replying to anonymous:
+ 10 more votes from me and my team. I didn't use trac for a long time because of silly unprofessional things like this (and the insistance on SQLite and the installation hastles of the templating engine). It's getting better and better but just needs a bit of polishing around the edges. Trac already has the processing engine to convert wiki markup to HTML, why not just reuse that in generating notification emails?
It will be done, hopefully for 0.12. It's not as "simple" as it may look, dealing with multipart emails that work properly with all (major) email clients is not straightforward.
I won't comment on the "silly unprofesionnal" things as it would be off-topic and useless.
comment:23 by , 17 years ago
Cc: | added |
---|
comment:24 by , 17 years ago
Cc: | added |
---|
comment:25 by , 17 years ago
Yes, I like the feature to be able to send more formatted emails as well. You got my vote!
comment:26 by , 16 years ago
Version: | 0.9.3 → 0.11-stable |
---|
Another vote for this feature. This would greatly improve the usability of ticket emails.
As it stands, seeing a bunch of wiki markup in your email message is often a bit… well.. horrible.. especially if it is complicated.
comment:27 by , 16 years ago
Cc: | removed |
---|
comment:28 by , 16 years ago
Cc: | added |
---|
comment:29 by , 16 years ago
We don't need votes, we need working code. If you'd like this feature please have a go at implementing it and submit your patches here. Please mention which email clients you have tested with.
Ideally it should work with Outlook, Thunderbird, Apple Mail Gmail and others. But that can be hard to achieve.
Useful links:
comment:30 by , 16 years ago
Cc: | added |
---|
Has anyone tried the AnnouncerPlugin? It is a bit of a hack but it works for me with Outlook 2003. It uses Genshi to create the html and sends a text alternative… also gened by Genshi… sadly it pretty much re-implements the whole trac notification system. It would be nice if Trac supported all this.
follow-up: 35 comment:31 by , 16 years ago
I've written a little tutorial in order to recieve HTML email notification with Trac 0.11. It's perfectible but it does the trick until an official support ! You can find it on http://trac-html-notification.alwaysdata.net
regards,
Akarzim
comment:32 by , 16 years ago
Cc: | added |
---|
comment:33 by , 16 years ago
Cc: | added |
---|
comment:34 by , 15 years ago
Cc: | added |
---|
comment:35 by , 15 years ago
Replying to trac-html-notification@…:
I've written a little tutorial in order to recieve HTML email notification with Trac 0.11. It's perfectible but it does the trick until an official support ! You can find it on http://trac-html-notification.alwaysdata.net
regards,
Akarzim
Can you send me your notification.py and ticket_notification_email.txt files for me ? I can't patch successfully in my trac.
comment:36 by , 15 years ago
Cc: | added |
---|
comment:37 by , 15 years ago
I have been told that the plan is to merge the th:AnnouncerPlugin into Trac in 0.13. I'm not sure if this plan is documented anywhere. Perhaps someone knowledgeable on the plan can elaborate.
comment:38 by , 15 years ago
The plan is to come up with a plan. We've started on TracDev/Proposals/Announcer. I think there is still a fair amount of work to be done.
comment:40 by , 14 years ago
Cc: | added |
---|
comment:41 by , 14 years ago
Cc: | added |
---|
comment:44 by , 14 years ago
Cc: | added |
---|
comment:45 by , 13 years ago
Cc: | added |
---|
Definitely a desired feature; if anything, at least allow a sane way to change the notification's Content-Type. This incredibly simple option took me several hours investigating & patching files instead of just writing a line to trac.ini. Ridiculous.
Relevant resource (from freakin' 2007): http://rickosborne.org/blog/2007/06/getting-trac-to-send-out-html-emails/
follow-ups: 47 49 comment:46 by , 13 years ago
Lots of solutions on this page. I'll add mine here. My goal was to modify the original PY scripts as little as possible.
Modified 'pyshared/trac/notification.py'
Original:
386 msg = MIMEText(body, 'html')
New:
386 msg = MIMEText(body, 'text')
Modified 'pyshared/trac/ticket/notification.py'
Added:
306 hdrs['Content-Type'] = 'text/html; charset=utf-8' 307 hdrs['PreferredFormat'] = 'text/html'
I copied ticket_notify_email.txt to my custom templates folder (set in trac.ini). My first draft, before all my awesome html formatting, works by adding this to the top of the file:
001 <html><body><pre>
and this to the bottom of the file:
020 </pre></body><html>
In my final template, I only left the <pre> wrapper around the $ticket_props part of the template. Everything else received html tags with styling.
I'm considering adding format_props_html. But the <pre> forces a fixed-width font, which solves my issue for now.
Hope this helps someone.
comment:47 by , 13 years ago
My "Original" and "New" modifications for "Modified 'pyshared/trac/notification.py'" lines are inverted.
Replying to Benjamin Saberin <ben@…>:
Lots of solutions on this page. I'll add mine here. My goal was to modify the original PY scripts as little as possible.
Modified 'pyshared/trac/notification.py'
Original:
386 msg = MIMEText(body, 'html')New:
386 msg = MIMEText(body, 'text')Modified 'pyshared/trac/ticket/notification.py'
Added:
306 hdrs['Content-Type'] = 'text/html; charset=utf-8' 307 hdrs['PreferredFormat'] = 'text/html'I copied ticket_notify_email.txt to my custom templates folder (set in trac.ini). My first draft, before all my awesome html formatting, works by adding this to the top of the file:
001 <html><body><pre>and this to the bottom of the file:
020 </pre></body><html>In my final template, I only left the <pre> wrapper around the $ticket_props part of the template. Everything else received html tags with styling.
I'm considering adding format_props_html. But the <pre> forces a fixed-width font, which solves my issue for now.
Hope this helps someone.
comment:48 by , 13 years ago
Cc: | added |
---|
follow-up: 50 comment:49 by , 13 years ago
Replying to Benjamin Saberin <ben@…>:
Lots of solutions on this page. I'll add mine here. My goal was to modify the original PY scripts as little as possible.
Hello,
I changed everything that you wrote down and I have customnotification with added html tags (bold, font style and ect..) BUT still in recieved mail header I have "plain text". Do I have to made new pyc and pyo files from existing (modified)? I have trac 0.12 and pyton 2.4.
Thank you.
comment:50 by , 13 years ago
Replying to ivan@…:
I changed everything that you wrote down and I have customnotification with added html tags (bold, font style and ect..) BUT still in recieved mail header I have "plain text". Do I have to made new pyc and pyo files from existing (modified)? I have trac 0.12 and pyton 2.4.
Anywhere the phrase
hdrs['Content-Type']
Appears you need to change it from plain text to 'text/html; charset=utf-8', so you can just grep the source code for the above phrase. In comment 45 I linked a guide to modifying the source code which is still relevant.
follow-ups: 52 55 comment:51 by , 13 years ago
I've created a patch for trac-0.12.3 from all the relevant sources mentioned here and elsewhere. Details and the diff file can be found in my blog here: http://ingenious-excerpts.blogspot.com/2012/02/trac-0123-and-html-notification.html
comment:52 by , 13 years ago
Replying to anonymous:
I've created a patch for trac-0.12.3 from all the relevant sources mentioned here and elsewhere. Details and the diff file can be found in my blog here: http://ingenious-excerpts.blogspot.com/2012/02/trac-0123-and-html-notification.html
Is there any hope any of this be folded into Trac 0.12.x still?
comment:53 by , 13 years ago
Cc: | added |
---|
comment:54 by , 13 years ago
Cc: | removed |
---|
follow-up: 56 comment:55 by , 13 years ago
Replying to anonymous:
I've created a patch for trac-0.12.3 from all the relevant sources mentioned here and elsewhere. Details and the diff file can be found in my blog here: http://ingenious-excerpts.blogspot.com/2012/02/trac-0123-and-html-notification.html
This works nice, but unfortunately it also breaks plugins such as tracopt.commit_updater. It is because the req object is not available in that plugin, and this is now required as you have added it as an extra parameter now in the notify function (wiki_to_html needs it). No idea on how to solve this problem yet, but I guess one could make a fallback if req is None.
comment:56 by , 13 years ago
There is a modified version here: http://maurice.priv.no/tech/?p=51
Replying to qontrol@…:
Replying to anonymous:
I've created a patch for trac-0.12.3 from all the relevant sources mentioned here and elsewhere. Details and the diff file can be found in my blog here: http://ingenious-excerpts.blogspot.com/2012/02/trac-0123-and-html-notification.html
This works nice, but unfortunately it also breaks plugins such as tracopt.commit_updater. It is because the req object is not available in that plugin, and this is now required as you have added it as an extra parameter now in the notify function (wiki_to_html needs it). No idea on how to solve this problem yet, but I guess one could make a fallback if req is None.
follow-up: 58 comment:57 by , 13 years ago
From this post - http://trac.edgewall.org/wiki/CommitTicketUpdater It sounds like the latest trac versions don't need to use the commit_updater plug in as notifications are taken care of in a different fashion in version 12 and up? But then I don't know if the hook is the same thing or not.
Has anyone figured out if it breaks anything else important?
comment:58 by , 13 years ago
Replying to anon:
Has anyone figured out if it breaks anything else important?
Usage of the new commit ticket updater is described in TracRepositoryAdmin#ExplicitSync. I'm not sure how that is relevant to this ticket though.
comment:59 by , 12 years ago
Cc: | added |
---|
comment:60 by , 12 years ago
I can verify that Maurice's patch from comment# 56 works in trac-0.12.3. Also posted here http://ingenious-excerpts.blogspot.co.at/2012/09/trac-0123-and-html-notifications-and.html#more
I'll look into this for trac-1.0 soon.
follow-up: 62 comment:61 by , 12 years ago
As the function trac.wiki.formatter.wiki_to_html is deprecated, a working patch for trac-1.0 has to use format_to_html instead. I tried to change the calls, but to no avail.
I tried to change this
'comment': wiki_to_html(change['comment'], env=self.env, req=self.req, absurls=True)
to this
context = Context.from_request(self.req, absurls=True) 'comment': format_to_html(change['comment'], self.env, context, escape_newlines=True)
I tried with escape_newlines and without, but it doesn't work. I got "TypeError: 'Environment' object is not callable" / AttributeError: 'Environment' object has no attribute 'get_hint' depending on the escape_newlines.
Any clues? I'd really like to whip up a proper patch for trac-1.0…
comment:62 by , 12 years ago
Replying to fizze:
context = Context.from_request(self.req, absurls=True) 'comment': format_to_html(change['comment'], self.env, context, escape_newlines=True)
It appears that you are just calling trunk/trac/wiki/formatter.py@11179:1541#L1533 with the arguments incorrectly ordered. The argument ordering does not match that of wiki_to_html
. Try:
'comment': format_to_html(self.env, context, change['comment'], escape_newlines=True)
comment:63 by , 12 years ago
Cc: | removed |
---|
comment:64 by , 12 years ago
Thanks, that seems to fix that problem. I also managed to fix the CommitTicketUpdater. All in trac-0.12.3 albeit.
I'll update to trac-1.0 soon, then I can work on a proper patch.
comment:65 by , 12 years ago
So from comments here and elsewhere, I was able to get this working in Trac 1.0.1dev-r11400. There are three files that need to be modified: source:trunk/trac/notification.py#473 msg = MIMEText(body, 'plain')
to msg = MIMEText(body, 'html')
, source:trunk/trac/ticket/notification.py:
-
notification.py
old new 29 29 from trac.util.datefmt import to_utimestamp 30 30 from trac.util.text import obfuscate_email_address, text_width, wrap 31 31 from trac.util.translation import deactivate, reactivate 32 from trac.web.api import Request 33 from trac.mimeview.api import Context 34 from trac.wiki.formatter import format_to_html 35 from StringIO import StringIO 36 import trac.perm as perm 32 37 33 38 34 39 class TicketNotificationSystem(Component): … … 178 183 ticket, when=modtime): 179 184 if not change['permanent']: # attachment with same time... 180 185 continue 186 187 try: 188 self.req 189 except: 190 self.req = None 191 192 if self.req is None: 193 self.env.log.warning("Req is None - a dummy Req is made so that wiki to html works") 194 tracurl = self.env.base_url.replace('https://','') 195 environ = {'REQUEST_METHOD':'GET','SCRIPT_NAME':'','SERVER_PORT':'443','SERVER_NAME':tracurl, 'wsgi.url_scheme': 'http', 'wsgi.input': StringIO('')} 196 self.req = Request(environ, None) 197 self.req.perm = perm.PermissionCache(self.env) 198 199 context = Context.from_request(self.req, absurls=True) 181 200 author = change['author'] 182 201 change_data.update({ 183 202 'author': self.obfuscate_email(author), 184 'comment': wrap(change['comment'], self.COLS, ' ', ' ', 185 '\n', self.ambiwidth) 203 'comment': format_to_html(self.env, context, change['comment'], escape_newlines=True) 186 204 }) 187 205 link += '#comment:%s' % str(change.get('cnum', '')) 188 206 for field, values in change['fields'].iteritems(): 189 207 old = values['old']
, $TRAC_ENV/templates/ticket_notify_email.txt (basically hijacked from http://trac-hacks.org/wiki/TracHtmlNotificationPatch, but also attached). The real question is whether I have managed to break other stuff in the process…
comment:66 by , 12 years ago
Cc: | added |
---|
comment:67 by , 12 years ago
Cc: | added |
---|
comment:68 by , 12 years ago
Cc: | added |
---|
comment:69 by , 11 years ago
Cc: | added |
---|
comment:70 by , 11 years ago
Cc: | removed |
---|
comment:71 by , 11 years ago
Cc: | removed |
---|
comment:72 by , 11 years ago
Cc: | added |
---|
I've created th:TracHtmlNotificationPlugin which substitutes the notification mail with HTML part. It works with Trac 0.12 and later, however, it is alpha quality.
comment:73 by , 11 years ago
Cc: | added |
---|
comment:74 by , 10 years ago
Cc: | added |
---|
comment:75 by , 10 years ago
Owner: | removed |
---|
comment:76 by , 15 months ago
The following diff (against 1.5.4) adds basic html capability to the default plain text TicketFormatter. When default_format.email = text/html
it will wrap the plain text email body into a <pre>
pair (and a bit of extra fiddling to maintain the links at the bottom).
diff --git a/trac/trac/ticket/notification.py b/trac/trac/ticket/notification.py index 8e1f351..54f7291 100644 --- a/trac/trac/ticket/notification.py +++ b/trac/trac/ticket/notification.py @@ -17,6 +17,7 @@ # import re +import html from trac.api import IEnvironmentSetupParticipant from trac.attachment import IAttachmentChangeListener @@ -131,16 +132,28 @@ class TicketFormatter(Component): def get_supported_styles(self, transport): yield 'text/plain', 'ticket' + yield 'text/html', 'ticket' def format(self, transport, style, event): if event.realm != 'ticket': return if event.category == 'batchmodify': - return self._format_plaintext_batchmodify(event) + content = self._format_plaintext_batchmodify(event) if event.category in ('attachment added', 'attachment deleted'): - return self._format_plaintext_attachment(event) + content = self._format_plaintext_attachment(event) else: - return self._format_plaintext(event) + content = self._format_plaintext(event) + + if style == 'text/html': + return self._htmlize(content) + else: + return content + + def _htmlize (self, content): + content = html.escape(content.decode()) + content = re.sub(r'<(http[^&]*)>', '<<a href="\\1">\\1</a>>', content) + pre = '<pre>%s</pre>' % content + return pre.encode('utf-8') def _format_plaintext(self, event): """Format ticket change notification e-mail (untranslated)"""
Ideally the notification message would look exactly the same as the ticket page. At the moment if I use wiki markup in the ticket comment I get raw markup in the notification message.