Modify

Opened 5 months ago

Closed 5 months ago

Last modified 5 months ago

#11576 closed enhancement (fixed)

Template for email content

Reported by: anonymous Owned by: hasienda
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 hasienda 5 months 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 5 months ago by hasienda

  • Priority changed from high to normal

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 follow-up: Changed 5 months ago by anonymous

  • Severity changed from critical to blocker
  • Type changed from defect to enhancement

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 5 months ago by rjollos

  • Severity changed from blocker to normal

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

Last edited 5 months ago by rjollos (previous) (diff)

comment:4 in reply to: ↑ 2 Changed 5 months ago by hasienda

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 ; follow-up: Changed 5 months ago by hasienda

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 5 months ago by hasienda

  • Resolution set to fixed
  • Status changed from new to closed

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 follow-up: Changed 5 months 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 5 months ago by hasienda

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 5 months ago by hasienda

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

comment:9 follow-up: Changed 5 months 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 5 months ago by hasienda

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 5 months 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 follow-up: Changed 5 months 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 5 months ago by rjollos

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 5 months ago by rjollos (previous) (diff)

comment:14 Changed 5 months 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 5 months ago by rjollos

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 5 months 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

Add Comment

Modify Ticket

Action
as closed .
as The resolution will be set. Next status will be 'closed'.
to The owner will be changed from hasienda. Next status will be 'closed'.
The resolution will be deleted. Next status will be 'reopened'.
Author


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

 
Note: See TracTickets for help on using tickets.