Version 4 (modified by 7 years ago) ( diff ) | ,
---|
Notification Customizations
TracNotification customizations can often be implemented with a short plugin. Some custom examples are given on this page.
Attachments in Notification Emails
This email decorator can be used to send new ticket attachments as email attachments with the notification emails.
- Create a single file plugin that implements IEmailDecorator:
# -*- coding: utf-8 -*- # # Copyright (C) 2017 Edgewall Software # All rights reserved. # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. The terms # are also available at http://trac.edgewall.org/wiki/TracLicense. # # This software consists of voluntary contributions made by many # individuals. For the exact contribution history, see the revision # history and logs, available at http://trac.edgewall.org/log/. from email.mime.application import MIMEApplication from trac.core import Component, implements from trac.notification.api import IEmailDecorator class AttachmentEmailDecorator(Component): implements(IEmailDecorator) # IEmailDecorator methods def decorate_message(self, event, message, charset): if event.category == 'attachment added': attachment = event.attachment filename = attachment.filename with attachment.open() as fd: part = MIMEApplication(fd.read(), Name=filename) part['Content-Disposition'] = 'attachment; filename="%s"' % filename message.attach(part)
See also: #3054
Reply-To Ticket Owner
Some projects want to replies to ticket email notifications to be directly sent to the ticket owner's email address.
- Create a single file plugin that implements IEmailDecorator:
# -*- coding: utf-8 -*- # # Copyright (C) 2017 Edgewall Software # All rights reserved. # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. The terms # are also available at http://trac.edgewall.org/wiki/TracLicense. # # This software consists of voluntary contributions made by many # individuals. For the exact contribution history, see the revision # history and logs, available at http://trac.edgewall.org/log/. from trac.core import Component, implements from trac.notification.api import IEmailDecorator from trac.notification.mail import RecipientMatcher, set_header class ReplyToTicketOwnerEmailDecorator(Component): """Use the ticket owner in the Reply-To header in notification emails.""" implements(IEmailDecorator) def decorate_message(self, event, message, charset): if event.realm != 'ticket': return owner = event.target['owner'] matcher = RecipientMatcher(self.env) owner = matcher.match_from_author(owner) if owner: set_header(message, 'Reply-To', owner, charset)
Variations
- Reply to ticket updater by changing
event.target['owner']
toevent.author
.
Reply-To Ticket Notification Emails
th:EmailtoTracScript and a small plugin to change the Reply-To address allow users to reply directly to notification emails to append comments to a ticket.
The Reply-To header is changed depending on the ticket id so replies are sent to for example 10044@trac-hacks.org
and can be appended to ticket #10044:
- Create a single file plugin that implements IEmailDecorator:
# -*- coding: utf-8 -*- # # Copyright (C) 2017 Edgewall Software # All rights reserved. # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. The terms # are also available at http://trac.edgewall.org/wiki/TracLicense. # # This software consists of voluntary contributions made by many # individuals. For the exact contribution history, see the revision # history and logs, available at http://trac.edgewall.org/log/. from trac.core import Component, implements from trac.config import Option from trac.notification.api import IEmailDecorator from trac.notification.mail import set_header class ReplyToTicketDecorator(Component): """Replaces the 'Reply-To' header for tickets with a dynamic email address. Uses a new config option 'ticket_smtp_replyto'. """ implements(IEmailDecorator) ticket_smtp_replyto = Option('notification', 'ticket_smtp_replyto', '__id__@localhost', """Reply-To address for ticket notification emails. ` __id__` is replaced with the ticket id.""") def decorate_message(self, event, message, charset): if event.realm == 'ticket': replyto = self.ticket_email_replyto.replace('__id__', str(event.target.id)) set_header(message, 'Reply-To', replyto, charset)
- Install and configure th:EmailtoTracScript.
See also: th:EmailtoTracScript, th:comment:4:ticket:10044