Edgewall Software

Opened 9 years ago

Closed 9 years ago

#11927 closed defect (fixed)

Email distributor generates wrong Content-Type header for text/html

Reported by: Jun Omae Owned by: Jun Omae
Priority: normal Milestone: 1.1.4
Component: notification Version: 1.1.3
Severity: normal Keywords:
Cc: Branch:
Release Notes:
  • Make EmailDistributor allow text/html format
  • Create always multipart/related message as root
  • Create multipart/alternative message with text/plain and text/html if text/html is preferred
  • Fallback to text/plain format when text/html formatter fails
API Changes:
Internal Changes:


I'm trying to add support of new notification system to th:TracHtmlNotificationPlugin (th:#12158).

Email distributor says sending event as text/html. However, Content-Type header in notification is text/plain.

04:46:34 PM Trac[mail] DEBUG: EmailDistributor is sending event as 'text/html' to: jun66j5@gmail.com
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
X-Trac-Realm: ticket
From: "My Project" <trac@localhost>
X-Trac-Version: 1.1.3
Precedence: bulk
Auto-Submitted: auto-generated
X-Mailer: Trac 1.1.3, by Edgewall Software
To: undisclosed-recipients: ;
References: <011.5820a89cc2c970d854f42757ba2afba4@localhost>
X-Trac-Project: My Project
In-Reply-To: <011.5820a89cc2c970d854f42757ba2afba4@localhost>
Date: Thu, 22 Jan 2015 07:53:18 -0000
Reply-To: trac@localhost
Message-ID: <026.b9afbec2d2e7f31d7df1cbbfe0b5fa89@localhost>
Subject: Re: [My Project] #1: test

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

Attachments (0)

Change History (5)

comment:1 by Peter Suter, 9 years ago

Right, EmailDistributor does not currently support HTML emails. I think at least we would have to pass 'html' to MIMEText:

  • trac/notification/mail.py

    diff -r 85498662a16a trac/notification/mail.py
    a b  
    324324            headers['Bcc'] = ', '.join(recipients)
    325325        headers['Reply-To'] = smtp_reply_to
    327         rootMessage = create_mime_text(output, 'plain', self._charset)
     327        mime_format = 'html' if format == 'text/html' else 'plain'
     328        rootMessage = create_mime_text(output, mime_format, self._charset)
    328329        for k, v in headers.iteritems():
    329330            set_header(rootMessage, k, v, self._charset)
    330331        for decorator in self.decorators:

Ideally we would create a multipart message with text and html.

in reply to:  1 ; comment:2 by Jun Omae, 9 years ago

Ideally we would create a multipart message with text and html.

Yeah. I tried it. See [d9207b9b/jomae.git].

in reply to:  2 comment:3 by Peter Suter, 9 years ago

Replying to jomae:

Ideally we would create a multipart message with text and html.

Yeah. I tried it. See [d9207b9b/jomae.git].

Looks great!

comment:4 by Jun Omae, 9 years ago

Owner: set to Jun Omae
Status: newassigned

Updated jomae.git@t11927 branch.

  • Added unit tests for trac.notification.mail
  • Fallback to text/plain when INotificationFormatter fails

comment:5 by Jun Omae, 9 years ago

Release Notes: modified (diff)
Resolution: fixed
Status: assignedclosed

Committed in [13689].

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain Jun Omae.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Jun Omae to the specified user.

Add Comment

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