Emails with attachment that are opened by Outlook 2003 do not display the attachment.

It appears that when the attachment is nested in a 'multipart/related' it is expected to be an embedded object by the mail client.
Other mail clients that I've tested with had no problem with this but at least Outlook 2003 didn't display the attachment.

This can be fixed by changing the multipart type to mixed, but then embedded objects (e.g. images) will appear as attachments too.

The patch below, wraps the the message body together with its embedded objects in a sub 'multipart/related' and then wraps this sub part together with the atatchment in a 'multipart/mixed'.

This resulted in both attachments and embedded objects correctly displayed in all email clients I had access to test with (gmail, yahoo, hotmail, thunderbord, outlook).

I wonder if others had the same problem and how they solved it. I'm not sure whether it's a problem with Outlook or just that Outlook is more strict than other clients about the message format. (This link talks about this problem and how to rewrite the message part from 'multipart/related' to 'multipart/mixed' in exchange server).

Index: sites/all/modules/mimemail/mimemail.inc
===================================================================
--- sites/all/modules/mimemail/mimemail.inc	(revision 758)
+++ sites/all/modules/mimemail/mimemail.inc	(working copy)
@@ -323,7 +323,10 @@
     }
   }
   else {
-    $content_type = 'multipart/related; type="multipart/alternative"';
+    // "multipart/mixed" should be the outer message part
+    // to ensures that if attachments exist they will 
+    // be displayed correctly in outlook (and potentially other mail clients)
+    $content_type = 'multipart/mixed';
 
     $text_part = array('Content-Type' => 'text/plain; charset=utf-8', 'content' => $text);
 
@@ -339,6 +342,11 @@
 
     if ($mime_parts) {
       $parts = array_merge($parts, $mime_parts);
+
+      // embedded objects need to to be wrapped together 
+      // with the body in a "multipart/related" part
+      $content = mimemail_multipart_body($parts, 'multipart/related; type="multipart/alternative"', TRUE);
+      $parts = array(array('Content-Type' => $content['headers']['Content-Type'], 'content' => $content['body']));
     }
   }
 

An example of how parts are nested hierarchically:

Before this change:

alternative body with attachment
--------------------------------
Content-Type: multipart/related
--Content-Type: multipart/alternative
----Content-Type: text/plain
----Content-Type: text/html
--Content-Type: application/msword

After this change:

alternative body with attachment
--------------------------------
Content-Type: multipart/mixed
--Content-Type: multipart/alternative
----Content-Type: text/plain
----Content-Type: text/html
--Content-Type: application/msword

alternative body with embedded objects and attachment
-----------------------------------------------------
Content-Type: multipart/mixed
--Content-Type: multipart/related
----Content-Type: multipart/alternative
------Content-Type: text/plain
------Content-Type: text/html
----Content-Type: image/png
--Content-Type: application/msword

alternative body (no embedded objects, no attachment)
-----------------------------------------------------
Content-Type: multipart/mixed
--Content-Type: multipart/alternative
----Content-Type: text/plain
----Content-Type: text/html

In the last example the outer part is probably redundant

Comments

sgabe’s picture

Status: Active » Needs work

The idea is not bad, but we have to make sure that this modification does not break other functionality.

We need test results for the following cases:

  • PLAIN message (simple)
  • PLAIN message with attachment
  • HTML message (simple)
  • HTML message with attachment
  • HTML message with embedded image
  • HTML message with embedded image and attachment

With a variety of clients:

  • Outlook (2007, 2003)
  • Hotmail
  • Yahoo! Mail
  • Gmail
  • Apple Mail
  • iPhone
  • Thunderbird
  • Windows live Mail (Desktop)

With the following mail engines:

According to the tests I made in the past months I think the current behavior works fine in most cases. If we can achieve to fix this for Outlook 2003 too that's awesome, but we shall not break anything.

arski’s picture

have the same issue with thunderbird.. :(

sgabe’s picture

Which version are you using? I have no issues with version 3.1.6.

arski’s picture

using alpha 6 yea..

I'm doing something like the following:

$attachments = array();
$attachments[] = array('filepath' => $file_path, 'filename' => $file_filename, 'filemime' => 'application/pdf');
mimemail($sender, $recipient, $subject, $body, FALSE, array(), NULL, $attachments);

And in the mimemail configuration screen, the format is set to Full HTML.

Thanks

sgabe’s picture

I mean what version of Thunderbird? In this issue it is irrelevant how do you send the attachments.

arski’s picture

oh, 3.0.10 in ubuntu lucid.

It works if I do mimemail($sender, $recipient, $subject, $body, TRUE, array(), NULL, $attachments); so with a plaintext body.. which is not so nice.. so maybe it IS relevant how the mail is sent? Just a possibility.

sgabe’s picture

I mean it is irrelevant for this issue in particular.

arski’s picture

OK. well, any ideas what's going wrong? :o

tecum’s picture

@geneticdrift Thanks, your patch is working fine for me.

One interesting side notice is, that that problem did only appear when using outlook behind an exchange server. Outlook users using Imap could read the attachments, Exchange users using OWA, too. Only users of the combination of Outlook and an Exchange server could not. The Version of Outlook seems unimportant.

@sgabe If we want the patch to be merged, how do you normally organize the tests? I will be able to perform some of the tests you mentioned but not all 180. Is it ok, if different people e.g. jointly fill following spreadsheet?

https://spreadsheets.google.com/ccc?key=0Anu6cqAJx7-XdHNWOXo4THdwV1g4MzA...

sgabe’s picture

That's a good call, I don't have any better idea right now. I would suggest to be more detailed, e.g. provide the username in every case and change the background color of the cell according to the result (red, yellow, green). Furthermore, since we need to do regression testing, we should handle that too somehow and monitor the results for different patches/modifications.

I am using a small module for testing to mass send emails. If there would be some people willing to help fixing this issue, I would finish that to be usable by others and publish it. However, any help with testing would be much appreciated.

sgabe’s picture

Removed, posted twice.

RedTop’s picture

I'm using Mime Mail to send out HTML webform results. Attachments were hidden before the patch. With patch it works beautifully. I've added details to the spreadsheet.

outlook 2003 client, behind exchange server.

sgabe’s picture

Status: Needs work » Needs review
StatusFileSize
new976 bytes

I did some testing and it seems that this change works well with Mime Mail's default engine without breaking anything, but the SMTP module can't handle this kind of nesting:

alternative body with embedded objects and attachment
-----------------------------------------------------
Content-Type: multipart/mixed
--Content-Type: multipart/related
----Content-Type: multipart/alternative
------Content-Type: text/plain
------Content-Type: text/html
----Content-Type: image/png
--Content-Type: application/msword

So some message comes through blank.

Please, test the attached patch and report back. If this really works with the default settings, it could be committed, then SMTP could provide the required support.

sgabe’s picture

attiks’s picture

StatusFileSize
new5.88 KB
new4.39 KB

Patch works for me, tested with windows live mail and outlook 2010

Before patch:
- attachment in live mail, but no paper clip visible so only visible after opening the email
- no attachment in outlook 2010, views as html page doesn't work, but owa works

After patch:
- attachment in live mail, with paper clip visible
- attachment in outlook, another happy client ;p

RedTop’s picture

Can we consider this fixed so the developer can (and is hopefully willing to) commit this to a dev version?

arski’s picture

you need to review and test the patch for that :)

RedTop’s picture

I already did Arski (see above), but I'm not in the position to commit this to the dev branch.

sgabe’s picture

Status: Needs review » Reviewed & tested by the community

I would like to create another alpha without this, because it will break emails for those who are using the SMTP module (see above). After that I will commit this to the development snapshot. In the meantime we can mark this as RTBC.

sgabe’s picture

Version: 6.x-1.0-alpha6 » 6.x-1.x-dev
Status: Reviewed & tested by the community » Fixed

Committed to Git for both branches.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.