Thursday, March 11, 2010

Email Content Type

I have a Drupal 6.15 instance that uses the SimpleNews(6.x-1.0) and Mimemail(6.x-1.0-alpha1) modules.

When I send a newsletter and receive it in Outlook 2007 I receive a poorly formatted text email with an html attachment. What I want is for the html attachment to be the email.

At first glance this is a client side problem with the client(Outlook) not interpreting the content-type correctly. But it is not real important if that is correct or not because I cannot expect all of the customers to change their email clients just for me. So I need to change something on the server side to force this to appear correctly in the email clients of the customers.

The content type I am seeing the received email is
Content-Type: multipart/alternative; charset="utf-8";



I read some forums and dug around in the Mimemail module code and decided to change the module to force the content type to multipart/mixed.

To do this added an extra line to mimemail.inc at line 321

$content_type = 'multipart/mixed';
return mimemail_multipart_body($parts, "$content_type; charset=utf-8");

After sending a few test emails this seems to have addressed the problem. There may be a better or more correct way to address this but it works for now.

UPDATE:
There was an update to the Mimemail Module that invalidates the line number I mentioned before.

The new version is 6.x-1.0-alpha2 dated 24 March 2010.

 The following line is the last line and the return from the function mimemail_html_body
return mimemail_multipart_body($parts, "$content_type; charset=utf-8"); 

What you want to do is force the mime type just before the function returns. So just prior to the return set the mimetype with the following line.

$content_type = 'multipart/mixed';

No comments:

Post a Comment