Mandril checks $message['attachements'] for an array of paths to files to attach to emails. The mimemail module handles attachments a little differently, it uses $message['params']['attachments'] and stores file info in an array.
As many contrib modules expect you'll be using mimemail for attachments (notably webform in my case), it formats the $message variable accordingly, and mandrill misses the attachements.
I have fixed this in the past using hook_mandrill_mail_alter, but I'm getting sick of doing it for each site I build, so here's a patch ;)
Comments
Comment #1
pjcdawkins commentedThe patch in the OP works for me. I am combining it with a patch (for Webform) in #2030479 that makes Webform recognise Mandrill as HTML-capable.
Comment #2
pjcdawkins commentedMy application needs to send attachments with customised names, so it passes the attachment 'filename' to Mime Mail. Mandrill uses 'name'. I've extended the OP's patch to handle this.
Comment #3
pjcdawkins commentedSorry, I left in a stray
watchdog()call.Comment #4
iztok commentedWanted to use this patch on commerce_billy_emai but they prepare the attachments in the array in "filecontent" (no URI to the file). With the above code I managed to fix that. If it makes sense I can prepare a patch.
Comment #5
gcbtripper54 & pjcdawkins, thanks for the great patch! Rolling it into the development code now.
@Iztok, it would be great to have that fix in the form of a patch. I would say as a general rule that's probably the thing to do if you have code you believe will be of use to others rather than pasting in code out of context. It saves a lot of time for those of us maintaining the module, which greatly increases the odds your code gets included!
Another benefit is that other users can more easily test the code before we get to it. For instructions on creating Drupal patches, if you need them: https://drupal.org/node/707484
I'd also want to make sure that this is the correct way to handle this, or if perhaps we should be altering the way commerce_billy_email deals with attachments to be more in line with what everyone else is doing. I'm closing this issue for now: if you want to, please open up a new one for the commerce_billy_mail compatibility.
Comment #6
gcbComment #8
pjcdawkins commentedJust a note to say that Mandrill will now send your Webform attachments! (if you have the latest Webform 7.x-4.x-dev)
#2030479: Support Mandrill (and other HTML-capable mail systems via _alter hook)
Comment #10
anybodyI'm sorry to reopen this but as maintainer of the commerce_billy_mail module I have to point out that the patch above is not quite enough as #2183235: Replace mimemail dependency shows (see feedback of Mandrill users!)
The patch is great for all cases where we have a file path. But as #4 says, there are cases where we just have a dynamically generated file that is never being saved to the file system. SMTP and Mimemail module support that via the "filecontent" attribute.
#4 provides a working solution which can also be found in a comment via a hook in #2183235: Replace mimemail dependency so it would make a lot of sense to also handle this condition.
Comment #11
klausiMandrill now also supports this in 2.x, see #2390441: Support inline file attachments with mimemail fileconten.