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
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | 911612_outlook_2010.png | 4.39 KB | attiks |
| #16 | 911612_live_mail.png | 5.88 KB | attiks |
| #14 | mimemail.911612_01.patch | 976 bytes | sgabe |
Comments
Comment #1
sgabe commentedThe 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:
With a variety of clients:
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.
Comment #3
arski commentedhave the same issue with thunderbird.. :(
Comment #4
sgabe commentedWhich version are you using? I have no issues with version 3.1.6.
Comment #5
arski commentedusing alpha 6 yea..
I'm doing something like the following:
And in the mimemail configuration screen, the format is set to Full HTML.
Thanks
Comment #6
sgabe commentedI mean what version of Thunderbird? In this issue it is irrelevant how do you send the attachments.
Comment #7
arski commentedoh, 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.
Comment #8
sgabe commentedI mean it is irrelevant for this issue in particular.
Comment #9
arski commentedOK. well, any ideas what's going wrong? :o
Comment #10
tecum commented@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...
Comment #11
sgabe commentedThat'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.
Comment #12
sgabe commentedRemoved, posted twice.
Comment #13
RedTop commentedI'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.
Comment #14
sgabe commentedI 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:
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.
Comment #15
sgabe commentedI filed an issue for this in SMTP: #1044534: Improve support for multipart/mixed messages
Comment #16
attiks commentedPatch 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
Comment #17
RedTop commentedCan we consider this fixed so the developer can (and is hopefully willing to) commit this to a dev version?
Comment #18
arski commentedyou need to review and test the patch for that :)
Comment #19
RedTop commentedI already did Arski (see above), but I'm not in the position to commit this to the dev branch.
Comment #20
sgabe commentedI 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.
Comment #21
sgabe commentedCommitted to Git for both branches.