[development] HTML emails

Matt Connolly matt at cabinetuk.com
Wed Jul 16 10:32:24 UTC 2008

Yes, I am trying to use "mimemail", just ported the code to Drupal 6  

The problem is that other modules that don't use mimemail duplicate  
some of its functionality, which makes sense when the module is not  

At the moment, I'm manually re-theming the other modules to not create  
"<html><head>" stuff to play nice with mimemail.

Ideally, though, you could set html head elements in an array in a  
similar fashion to for FORM API so that mimemail (or any HTML aware  
drupal mail module) could interpret and include in the constructed  
email message in the correct place. ie: returning a structured array  
instead of a flat string. Although this may be contrary to how theme  
functions work...

It makes sense to me that modules should only create the content that  
goes in a <DIV> tag, just like building a block on the page. However,  
many modules call drupal_add_css or drupal_add_js which ultimately  
gets added to the page when it's rendered. I think email generation  
should have the same ability to include CSS files (which should go in  
the <HEAD> tag, not a <DIV>)

I notice that mimemail does in fact get the CSS files from drupal and  
the current theme (in the absence of a mail.css file) so you can  
simply call drupal_add_cs() from a theme function that generates  
email.... just confusing if you're generating an email, and then a  
resulting page at the same time.....


On 16/07/2008, at 10:46 AM, Nathaniel Catchpole wrote:

> There's a patch here that's not had much attention for over a year  
> but would provide better support in core: http://drupal.org/node/28604
> You should also look at http://drupal.org/project/mimemail
> Nat
> On Wed, Jul 16, 2008 at 10:22 AM, Omar Abdel-Wahab  wrote:
> +1
> I strongly would love to have D7 send HTML e-mails.
> At least 20 modules will benefit from this step.
> Omar
> Matt Connolly wrote:
> I haven't looked at drupal 7 yet, so I'm throwing this out there for  
> discussion.
> The D6 mail api seems like it's pretty much designed for plain text  
> emails, however, a module's implementation of hook_mail can clearly  
> set the headers of the mail to "Content-Type: text/html;  
> charset=utf-8" and send rich text.
> For example, I'm looking at using "forward" module for the "email  
> this page" link on a node, and the "simplenews" module, which uses  
> "mimemail" to send rich emails, including attachments. Both  
> "forward" and "mimemail" modules create a html header.
> The problem occurs when a module implements "drupal_mail_wrapper()"  
> to build a html header when hook_mail has already done that - you  
> can easily end up with bodies like:
> <!doctype... <-- from drupal_mail_wrapper()
> <html>
> <head>...</head>
> <body><div....
> <!doctype. <-- from hook_mail()
> <html>
> <head> ... etc.
> Because there are two opportunities to create the html "head" for  
> the message: in hook_mail and drupal_mail_wrapper.
> I'm throwing this out there for discussion, I think that the  
> hook_mail should construct the message in a similar fashion to the  
> Form API, specifying a theme for rendering the body part of the  
> message (ie what goes in the <body> tag) and anything special that  
> needs to go in the head as attributes.
> That way the message can be constructed only once.
> Besides, email clients have been HTML friendly for a *long* time, so  
> I don't see why Drupal shouldn't have an interface that understands  
> rich email messages.
> Thoughts?
> Matt

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20080716/4ae107de/attachment.htm 

More information about the development mailing list