Edgewall Software
Modify

Opened 19 years ago

Last modified 14 months ago

#2625 new enhancement

Add option to send HTML mail messages

Reported by: tomek.piatek@… 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 Emmanuel Blot, 19 years ago

Keywords: notification email added

comment:2 by anonymous, 19 years ago

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.

comment:3 by Peter Bruin, 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 Emmanuel Blot, 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 ander.tenno@…, 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 anonymous, 19 years ago

Cc: ander.tenno@… added

comment:7 by Russell Hind <rhind@…>, 19 years ago

Cc: rhind@… 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 ander.tenno@…, 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 anonymous, 19 years ago

Cc: broohaha@… added

comment:10 by anonymous, 19 years ago

Cc: s.mitchell@… added

comment:11 by lewis.francis@…, 19 years ago

Cc: lewis.francis@… 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 oscarmv@…, 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 c00i90wn <c00i90wn@…>, 18 years ago

Cc: c00i90wn@… added

comment:14 by Willem Kokke <mail@…>, 18 years ago

Cc: mail@… 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 Markus Tacker <m@…>, 18 years ago

Cc: m@… added

comment:16 by benjamin.azan@…, 18 years ago

Cc: benjamin.azan@… added

This improvement would be extremly usefull.

comment:17 by Emmanuel Blot, 18 years ago

See also #4516

comment:18 by Christian Boos, 18 years ago

Component: generalnotification
Milestone: 0.12
Owner: changed from Jonas Borgström to Emmanuel Blot

+ this should also be a user preference.

comment:19 by diego.gentoo@…, 17 years ago

Cc: diego.gentoo@… added

Any news?

in reply to:  19 comment:20 by Emmanuel Blot, 17 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

comment:21 by anonymous, 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?

in reply to:  21 comment:22 by Emmanuel Blot, 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 daniel.oconnor@…, 17 years ago

Cc: daniel.oconnor@… added

comment:24 by Nicolas Marchildon <nicolas@…>, 17 years ago

Cc: nicolas@… added

I came here because I wanted to have clickable links to tickets referenced in wiki format. Examples:

Therefore, I'm putting my vote on this.

comment:25 by PP Edenburg, 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 Kamil Kisiel <kamil@…>, 16 years ago

Version: 0.9.30.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 rhind@…, 16 years ago

Cc: rhind@… removed

comment:28 by jetcat@…, 16 years ago

Cc: jetcat@… added

comment:29 by diroussel+trac@…, 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 dbytesguard-trackhacks@…, 16 years ago

Cc: dbytesguard-trackhacks@… 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.

comment:31 by trac-html-notification@…, 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 ericacm@…, 16 years ago

Cc: ericacm@… added

comment:33 by anonymous, 15 years ago

Cc: alejandro.popov@… added

comment:34 by Ryan Ollos <ryano@…>, 15 years ago

Cc: ryano@… added

in reply to:  31 comment:35 by anonymous, 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 christophe.prevost@…, 15 years ago

Cc: christophe.prevost@… added

comment:37 by Ryan Ollos <ryano@…>, 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 rcorsaro, 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 Isaac Sutherland <isaacsutherland@…>, 14 years ago

Cc: isaacsutherland@… added

comment:41 by bill@…, 14 years ago

Cc: bill@… added

comment:42 by the3illings@…, 14 years ago

Cc: the3illings@… added

Are there any plan to get that running in a 0.12.x or 0.13?

comment:43 by Christian Boos, 14 years ago

Sorry, no. This feature is on the long term plan.

comment:44 by Olle <olle@…>, 13 years ago

Cc: olle@… added

comment:45 by kofal002@…, 13 years ago

Cc: kofal002@… 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/

comment:46 by Benjamin Saberin <ben@…>, 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.

in reply to:  46 comment:47 by Benjamin Saberin <ben@…>, 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 Marcus Lindblom Sonestedt <macke@…>, 13 years ago

Cc: macke@… added

in reply to:  46 ; comment:49 by ivan@…, 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.

in reply to:  49 comment:50 by anonymous, 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.

comment:51 by anonymous, 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

in reply to:  51 comment:52 by anonymous, 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 michael.illing@…, 13 years ago

Cc: michael.illing@… added

comment:54 by the3illings@…, 13 years ago

Cc: the3illings@… removed

in reply to:  51 ; comment:55 by qontrol@…, 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.

in reply to:  55 comment:56 by anonymous, 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.

comment:57 by anon, 12 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?

in reply to:  57 comment:58 by Ryan J Ollos <ryano@…>, 12 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 Ethan Jucovy <ethan.jucovy@…>, 12 years ago

Cc: ethan.jucovy@… added

comment:60 by fizze, 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.

comment:61 by fizze, 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…

in reply to:  61 comment:62 by Ryan J Ollos <ryan.j.ollos@…>, 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 kofal002@…, 12 years ago

Cc: kofal002@… removed

comment:64 by fizze, 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 dave@…, 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  
    2929from trac.util.datefmt import to_utimestamp
    3030from trac.util.text import obfuscate_email_address, text_width, wrap
    3131from trac.util.translation import deactivate, reactivate
     32from trac.web.api import Request
     33from trac.mimeview.api import Context
     34from trac.wiki.formatter import format_to_html
     35from StringIO import StringIO
     36import trac.perm as perm
    3237
    3338
    3439class TicketNotificationSystem(Component):
     
    178183                                                ticket, when=modtime):
    179184                if not change['permanent']: # attachment with same time...
    180185                    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)
    181200                author = change['author']
    182201                change_data.update({
    183202                    '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)
    186204                    })
    187205                link += '#comment:%s' % str(change.get('cnum', ''))
    188206                for field, values in change['fields'].iteritems():
    189207                    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 Dave Lasley <dave@…>, 12 years ago

Cc: dave@… added

comment:67 by lkraav <leho@…>, 11 years ago

Cc: leho@… added

comment:68 by charles_ymt@…, 11 years ago

Cc: charles_ymt@… added

comment:69 by nielsen@…, 11 years ago

Cc: nielsen@… added

comment:70 by Ryan J Ollos, 11 years ago

Cc: ryano@… removed

comment:71 by Olle Larson <olle@…>, 11 years ago

Cc: olle@… removed

comment:72 by Jun Omae, 11 years ago

Cc: Jun Omae 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 josh@…, 10 years ago

Cc: josh@… added

comment:74 by lee@…, 10 years ago

Cc: lee@… added

comment:75 by Ryan J Ollos, 9 years ago

Owner: Emmanuel Blot removed

comment:76 by anonymous, 14 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'&lt;(http[^&]*)&gt;', '&lt;<a href="\\1">\\1</a>&gt;', content)
+        pre = '<pre>%s</pre>' % content
+        return pre.encode('utf-8')
 
     def _format_plaintext(self, event):
         """Format ticket change notification e-mail (untranslated)"""

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The ticket will remain with no owner.
The ticket will be disowned.
as The resolution will be set. Next status will be 'closed'.
The owner will be changed from (none) to anonymous. Next status will be 'assigned'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.