Modify

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#11576 closed enhancement (fixed)

Template for email content

Reported by: anonymous Owned by: Steffen Hoffmann
Priority: normal Component: AnnouncerPlugin
Severity: normal Keywords:
Cc: Trac Release:

Description

Using the default trac (v 12.5) notification system, the email content sent via email is the one generated based on ticket_notify_email.txt in trac/templates.

Now, when AnnouncerPlugin is enabled, with the following configuration:

[announcer]
ticket_email_subject = #${ticket.id}: ${ticket['summary']}.
ticket_email_header_fields = owner, reporter, milestone, priority, severity
...all the other values from [notification] section....

the plugin sends email but not with the template content. Is there a way to customize the content? For now there's no documentation about templating in http://trac-hacks.org/wiki/AnnouncerPlugin#Formatters

Is templating already supported? As long it is not supported I have to go back to trac notification.

Attachments (1)

20140223_announcer-trunk-i18n-template-rendering-fix.patch (544 bytes) - added by Steffen Hoffmann 10 years ago.
add i18n helper function to data object for ticket announcement text template rendering

Download all attachments as: .zip

Change History (17)

comment:1 in reply to:  description Changed 10 years ago by Steffen Hoffmann

Priority: highnormal

Replying to anonymous:

Is there a way to customize the content? For now there's no documentation about templating in http://trac-hacks.org/wiki/AnnouncerPlugin#Formatters

Is templating already supported? As long it is not supported I have to go back to trac notification.

Is this meant to be a complaint about documentation? Obviously there has been no advertising about templating capabilities, so it cannot be a software bug, nor do I find it that critical for average applications. Finally the priority shall be left entirely to developers and core contributors. Without a patch or at least an idea there is not much to do immediately.

Nevertheless I'll go and look at the code, because I already wanted to do that long ago.

Btw, anonymous users can still leave an email address, that helps extraordinarily in reaching reporters and commenters for resolving issues.

comment:2 Changed 10 years ago by anonymous

Severity: criticalblocker
Type: defectenhancement

Apologize me for the priority setting. But I believe that the template feature is important and it is missing with respect to the core trac notification system, a miss so big that is blocking the plugin adoption. And it's a pity because it's great for the architecture and functionalities, like the resolver SessionEmailResolver, and for potentiality like future(?) LdapEmailResolver.

What idea is needed to implement the template feature? A port of templating functionality from core notification system is possible?

Thank you much Nik

comment:3 Changed 10 years ago by Ryan J Ollos

Severity: blockernormal

It's fine to mention that it's a blocker for you. Please let the developers set the priority though.

Version 1, edited 10 years ago by Ryan J Ollos (previous) (next) (diff)

comment:4 in reply to:  2 Changed 10 years ago by Steffen Hoffmann

Replying to anonymous:

Apologize me for the priority setting. But I believe that the template feature is important and it is missing with respect to the core trac notification system, a miss so big that is blocking the plugin adoption.

For you. Don't take it personally, but as with Trac core code rules. Not much to work with here, right?

And it's a pity because it's great for the architecture and functionalities, like the resolver SessionEmailResolver, and for potentiality like future(?) LdapEmailResolver.

I really appreciate, that you do value the plugin high and thanks for your interest in its development.

What idea is needed to implement the template feature?

Dunno, non yet. I think, I still need to look at the code to give a better comment.

A port of templating functionality from core notification system is possible?

Trac is designed for modularity from the ground. Its component architecture already shares such great functionality with any modules including Trac plugins, so it could be used right-away, if not already done.

But beware, that you'll loose i18n-related features as much as you customize templates, if you can't extend message catalogs as well, what shall become technically possible, but is currently not ready.

comment:5 in reply to:  description ; Changed 10 years ago by Steffen Hoffmann

Replying to anonymous:

Using the default trac (v 12.5) notification system, the email content sent via email is the one generated based on ticket_notify_email.txt in trac/templates.

Now, when AnnouncerPlugin is enabled, with the following configuration: (snip) the plugin sends email but not with the template content. Is there a way to customize the content? For now there's no documentation about templating in http://trac-hacks.org/wiki/AnnouncerPlugin#Formatters

It is supported, and you must have just overlooked it. Similar to Trac core customization is not supported from configuration (your reported attempt) but by modifying a template: In announcer/formatters.py you'll see, that it uses ticket_email_plaintext.txt.

I'll extend our wiki documentation accordingly as a way to resolve this ticket.

comment:6 in reply to:  5 Changed 10 years ago by Steffen Hoffmann

Resolution: fixed
Status: newclosed

Replying to hasienda:

I'll extend our wiki documentation accordingly as a way to resolve this ticket.

Done, adding content to the Formatter section of that page. Thanks for pointing at this missing part in our documentation.

comment:7 Changed 10 years ago by anonymous

Good to know that template is already supported.

May be the documentation should clarify that the announcer template format differs from the one used for trac notification, possibly with a link to the format guideline. Indeed if we rename the template file from /templates/ticket_notify_email.txt to /templates/ticket_email_plaintext.txt, the announcer fails and sends the notification disclosing details via email, not using the template itself.

2014-02-23 14:02:13,547 Trac[api] ERROR: AnnouncementSystem failed.
Traceback (most recent call last):
  File "build/bdist.linux-x86_64/egg/announcer/api.py", line 584, in _real_send
    evt)
  File "build/bdist.linux-x86_64/egg/announcer/distributors/mail.py", line 330, in distribute
    self._do_send(transport, event, k, v, fmtdict[k])
  File "build/bdist.linux-x86_64/egg/announcer/distributors/mail.py", line 437, in _do_send
    output = formatter.format(transport, event.realm, format, event)
  File "build/bdist.linux-x86_64/egg/announcer/formatters.py", line 78, in format
    return self._format_plaintext(event)
  File "build/bdist.linux-x86_64/egg/announcer/formatters.py", line 152, in _format_plaintext
    output = stream.render('text')
  File "/usr/lib/python2.7/dist-packages/genshi/core.py", line 183, in render
    return encode(generator, method=method, encoding=encoding, out=out)
  File "/usr/lib/python2.7/dist-packages/genshi/output.py", line 57, in encode
    return _encode(''.join(list(iterator)))
  File "/usr/lib/python2.7/dist-packages/genshi/output.py", line 569, in __call__
    for event in stream:
  File "/usr/lib/python2.7/dist-packages/genshi/core.py", line 288, in _ensure
    for event in stream:
  File "/usr/lib/python2.7/dist-packages/genshi/template/base.py", line 605, in _include
    for event in stream:
  File "/usr/lib/python2.7/dist-packages/genshi/template/base.py", line 565, in _flatten
    result = _eval_expr(data, ctxt, vars)
  File "/usr/lib/python2.7/dist-packages/genshi/template/base.py", line 277, in _eval_expr
    retval = expr.evaluate(ctxt)
  File "/usr/lib/python2.7/dist-packages/genshi/template/eval.py", line 178, in evaluate
    return eval(self.code, _globals, {'__data__': data})
  File "/srv/trac/yoodev/templates/ticket_email_plaintext.txt", line 1, in <Expression u"_('Ticket URL: <%(link)s>', link=ticket.link)">
    $ticket_body_hdr
  File "/usr/lib/python2.7/dist-packages/genshi/template/eval.py", line 277, in _die
    raise UndefinedError(self._name, self._owner)
UndefinedError: "_" not defined
2014-02-23 14:02:13,547 Trac[api] DEBUG: AnnouncementSystem sent event in 0.06 seconds.

comment:8 in reply to:  7 Changed 10 years ago by Steffen Hoffmann

Replying to anonymous:

Good to know that template is already supported.

Yes.

May be the documentation should clarify that the announcer template format differs from the one used for trac notification,

Why do you think this?

... if we rename the template file from /templates/ticket_notify_email.txt to /templates/ticket_email_plaintext.txt, the announcer fails and sends the notification disclosing details via email, not using the template itself.

2014-02-23 14:02:13,547 Trac[api] ERROR: AnnouncementSystem failed.
Traceback (most recent call last):
  File "build/bdist.linux-x86_64/egg/announcer/api.py", line 584, in _real_send
    evt)
...
  File "/usr/lib/python2.7/dist-packages/genshi/template/eval.py", line 178, in evaluate
    return eval(self.code, _globals, {'__data__': data})
  File "/srv/trac/yoodev/templates/ticket_email_plaintext.txt", line 1, in <Expression u"_('Ticket URL: <%(link)s>', link=ticket.link)">
    $ticket_body_hdr
  File "/usr/lib/python2.7/dist-packages/genshi/template/eval.py", line 277, in _die
    raise UndefinedError(self._name, self._owner)
UndefinedError: "_" not defined
2014-02-23 14:02:13,547 Trac[api] DEBUG: AnnouncementSystem sent event in 0.06 seconds.

This is a missing i18n helper function, and a reminder, that we fail to support template content translation yet. I'm longing for that for years now, but this is a different issue. If you're up for testing our trunk branch, I could provide a quick fix.

Changed 10 years ago by Steffen Hoffmann

add i18n helper function to data object for ticket announcement text template rendering

comment:9 Changed 10 years ago by anonymous

Tested the template /templates/ticket_email_plaintext.txt by simply putting "hello world", no symbols, se we can expect the announcer email with just "hello world" as content, but still get email with all the details.

Ok will download the trunk version :)

In the format guideline we can list some variable bindings useful for templating about ticket wanted details and trac environment. Also mention the following link about the format, if this applies : http://genshi.edgewall.org/wiki/Documentation/text-templates.html

Nik

comment:10 in reply to:  9 Changed 10 years ago by Steffen Hoffmann

Replying to anonymous:

Tested the template /templates/ticket_email_plaintext.txt by simply putting "hello world", no symbols, se we can expect the announcer email with just "hello world" as content, but still get email with all the details.

Ok will download the trunk version :)

I see. With the patch applied you should get a working system at best, or new 'details'. Please report them back, and I'll try to get it going ASAP. Thanks a lot for giving it a shot. Your help in testing is much appreciated.

In the format guideline we can list some variable bindings useful for templating about ticket wanted details and trac environment. Also mention the following link about the format, if this applies : http://genshi.edgewall.org/wiki/Documentation/text-templates.html

Yes, this is the correct reference. Good point, thanks.

comment:11 Changed 10 years ago by anonymous

Downloaded the AnnouncerPlugin trunk 13714 and it works! :) I've copied the content of ticket_notify_email.txt into ticket_email_plaintext.txt and it works too, reading that template! Goood! :)) Best regards Nik

comment:12 Changed 10 years ago by anonymous

Apologize me (comment:11), it was working under trac notification system...

With AnnouncerPlugin trunk 13714 enabled (and trac notification disabled) it results as:

  File "/usr/lib/python2.7/dist-packages/genshi/template/base.py", line 277, in _eval_expr
    retval = expr.evaluate(ctxt)
  File "/usr/lib/python2.7/dist-packages/genshi/template/eval.py", line 178, in evaluate
    return eval(self.code, _globals, {'__data__': data})
  File "/srv/trac/yoodev/templates/ticket_email_plaintext.txt", line 1, in <Expression u"_('Ticket URL: <%(link)s>', link=ticket.link)">
    $ticket_body_hdr
  File "/usr/lib/python2.7/dist-packages/genshi/template/eval.py", line 277, in _die
    raise UndefinedError(self._name, self._owner)
UndefinedError: "_" not defined

Changed the template so that it does not contain symbols, just for test purpose, and now:

2014-02-28 11:53:35,502 Trac[web_ui] ERROR: Failure sending notification on change to ticket #3: AttributeError: Cannot find an implementation of the "IEmailSender" interface named "SmtpEmailSender".  Please update the option notification.email_sender in trac.ini.
[notification]
email_sender = SmtpEmailSender

comment:13 in reply to:  12 Changed 10 years ago by Ryan J Ollos

Replying to anonymous:

2014-02-28 11:53:35,502 Trac[web_ui] ERROR: Failure sending notification on change to ticket #3: AttributeError: Cannot find an implementation of the "IEmailSender" interface named "SmtpEmailSender".  Please update the option notification.email_sender in trac.ini.
[notification]
email_sender = SmtpEmailSender

It is probably just a matter of needing to enable the SmtpEmailSender component. What components are shown as enabled for announcer in the [components] section of trac.ini? You'll need one of the following:

announcer.* = enabled

or

announcer.distributors.* = enabled

or

announcer.distributors.mail.* = enabled

or

announcer.distributors.mail.SmtpEmailSender = enabled
Last edited 10 years ago by Ryan J Ollos (previous) (diff)

comment:14 Changed 10 years ago by anonymous

This was already enabled

announcer.* = enabled

Just to clear ideas, this should impact announcer or not?

trac.notification.smtpemailsender = enabled

Added this

announcer.distributors.mail.SmtpEmailSender = enabled

and it works.

May be the message could be improved from

Cannot find an implementation of the "IEmailSender" interface named "SmtpEmailSender".  Please update the option notification.email_sender in trac.ini.

to

Cannot find an implementation of the "IEmailSender" interface named "SmtpEmailSender".  Please, in trac.ini, check the option [announcer] email_sender = INTERFACE_NAME and enable it with  announcer.distributors.mail.INTERFACE_NAME = enabled 

Please do you have any link to a list of possible bindings and a small genshi template sample to show how to bind to ticket fields? Thanks Nik

comment:15 Changed 10 years ago by Ryan J Ollos

The [components] rules are inherited, meaning announcer.distributors.mail.SmtpEmailSender = enabled should not be needed when announcer.* = enabled, unless there is an intermediate disabled rule, such as announcer.distributors.* = disabled.

I think trac.notification.smtpemailsender will not impact AnnouncerPlugin, but I'll defer to hasienda for a definite answer.

Improving the error message was discussed in comment:17:ticket:10980, and done for Trac 1.0.2 in trac:#11427.

For plain text emails, you can refer to TracNotification#Customizingthee-mailcontent on customizing the template. announcerplugin/trunk/announcer/templates/ticket_email_mimic.html@12359:119-120#L112 shows how to work with the ticket fields in an html template.

comment:16 Changed 10 years ago by anonymous

About the plain text email template (comment:15) I'm afraid that there are still some differences between trac notification and announcer:

  1. The $project triggers an error. That variable works in the trac notification but not in the announcer.
2014-03-07 10:31:17,995 Trac[api] ERROR: AnnouncementSystem failed.
Traceback (most recent call last):
  File "build/bdist.linux-x86_64/egg/announcer/api.py", line 584, in _real_send
    evt)
  File "build/bdist.linux-x86_64/egg/announcer/distributors/mail.py", line 330, in distribute
    self._do_send(transport, event, k, v, fmtdict[k])
  File "build/bdist.linux-x86_64/egg/announcer/distributors/mail.py", line 437, in _do_send
    output = formatter.format(transport, event.realm, format, event)
  File "build/bdist.linux-x86_64/egg/announcer/formatters.py", line 78, in format
    return self._format_plaintext(event)
  File "build/bdist.linux-x86_64/egg/announcer/formatters.py", line 152, in _format_plaintext
    output = stream.render('text')
  File "/usr/lib/python2.7/dist-packages/genshi/core.py", line 183, in render
    return encode(generator, method=method, encoding=encoding, out=out)
  File "/usr/lib/python2.7/dist-packages/genshi/output.py", line 57, in encode
    return _encode(''.join(list(iterator)))
  File "/usr/lib/python2.7/dist-packages/genshi/output.py", line 569, in __call__
    for event in stream:
  File "/usr/lib/python2.7/dist-packages/genshi/core.py", line 288, in _ensure
    for event in stream:
  File "/usr/lib/python2.7/dist-packages/genshi/template/base.py", line 605, in _include
    for event in stream:
  File "/usr/lib/python2.7/dist-packages/genshi/template/base.py", line 565, in _flatten
    result = _eval_expr(data, ctxt, vars)
  File "/usr/lib/python2.7/dist-packages/genshi/template/base.py", line 277, in _eval_expr
    retval = expr.evaluate(ctxt)
  File "/usr/lib/python2.7/dist-packages/genshi/template/eval.py", line 178, in evaluate
    return eval(self.code, _globals, {'__data__': data})
  File "/srv/trac/yoodev/templates/ticket_email_plaintext.txt", line 3, in <Expression u'project.name'>
    Ticket: $ticket.link
  File "/usr/lib/python2.7/dist-packages/genshi/template/eval.py", line 316, in lookup_attr
    val = getattr(obj, key)
  File "/usr/lib/python2.7/dist-packages/genshi/template/eval.py", line 277, in _die
    raise UndefinedError(self._name, self._owner)
UndefinedError: "project" not defined

  1. In the rendered and sent email, the variable contents are empty, even these: $ticket.id $summary $ticket.link

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Steffen Hoffmann.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.