Edgewall Software

Version 3 (modified by Peter Suter, 7 years ago) ( diff )

Minor tweaks

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.

  1. 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 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:

  1. 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)
    
  2. Install and configure th:EmailtoTracScript.

See also: th:EmailtoTracScript, th:comment:4:ticket:10044

Note: See TracWiki for help on using the wiki.