Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I've got a really simple test case, so I can tell you the problem named in the title.
I've upgraded to the latest beta1 and wondered why my emails no more contained attachments. I looked around in my other modules but found no reason. So I changed mimemail to the latest .dev version without luck. Attachments were still not working.
(Caches cleared etc.) ;)
Finally i downgraded to alpha2 WITHOUT ANY OTHER MODIFICATIONS and now attachements worked again!
Could someone else please have a look if this is reproducable?
Comment | File | Size | Author |
---|---|---|---|
#21 | attachments_prepared_array_not_accepted-2113961-21.patch | 1.13 KB | anrikun |
|
Comments
Comment #1
arkestra CreditAttribution: arkestra commentedSeconded -- rolling back to alpha2 fixed the issue.
Noticed the issue through integration with mass_contact module.
Comment #2
howdytom CreditAttribution: howdytom commentedYes, I am able to reproduce this issue! Using Rules with Mime Mail 7.x-1.x-beta1 no longer sends out emails with attachments.
Logfile:
The reaction rule signup (rules_ signup_e_mail_pdf) fails the integrity check and cannot be executed. Error: Missing configuration for parameter key.
It’s working with 7.x-1.0-alpha2!
Comment #3
sgabe CreditAttribution: sgabe commented@howdytom: You should update your rules settings as stated in the release note:
Comment #4
howdytom CreditAttribution: howdytom commented@sgabe: You're absolutely right! I've missed the release note! Sorry.
Once I've set the unique key for our Rules action Mime Mail 7.x-1.x-beta1 is working again.
Comment #5
AnybodyFor your information: In our case it is not a rule, but a mail sent from a module.
This is the drupal_mail call:
Do you see something wrong there or is it a problem in mimemail?
After the update no more attachments are working, as described initially.
Comment #6
sgabe CreditAttribution: sgabe commentedCheck the location of your attachments. The files cannot be outside the public files directory just if you enable the "Send arbitrary files" permission.
Comment #7
AnybodyThe files have to be in the tmp directory in this case, because they may not be saved permanently (invoices).
So perhaps it would make sense to provide a separate permission for this case? (https://api.drupal.org/api/drupal/includes!file.inc/function/file_direct...)
These emails are sent by system, the function of this module, as shown above, is triggered by a rule on cron run. Is there a possibility to tell drupal_mail for mime_mail to always send the email with a specific user or role? Else I think I would have to give the permission you mentioned for all roles, which is not secure in my eyes.
Any ideas or hints? :)
Thanks a lot!
Comment #8
sgabe CreditAttribution: sgabe commentedThe temporary directory can be set and usually defaults to be inside the public files directory.
Comment #9
AnybodyI've now activated the "Send arbitrary files" permission for all roles including guest, but the mails still don't contain any attachments. If I downgrade, everything works.
Comment #10
m1r1k CreditAttribution: m1r1k commented@Anybody check "Site-wide default MailSystemInterface class" here admin/config/system/mailsystem, you should have MimeMailSystem class selected, because default Drupal class doesn't know how to handle attachments at all.
Comment #11
AnybodyThank you for your reply m1r1k,
but I'm sorry, that's already the case. Everything is and was set to "MimeMailSystem". The theme is also selected to be the one required.
Comment #12
trentl CreditAttribution: trentl commentedI don't know if this helps, but it seems to have to do with spaces in the filenames. I rolled back go Alpha2 and Mime Mail successfully sends attachments with spaces in the file names. Beta1 does not.
Steps to reproduce:
1) Create form with file field component
2) Configure form and check "send files as attachments"
3) Test form by uploading file name with spaces
Result - if file name has spaces, it will not be sent as an attachment. Using alpha2 version does not exhibit this behavior.
i will note that I am using "private files" setting
Comment #13
AnybodyIn my case the file does not contain spaces.
Comment #14
AnybodyIt seems that I could finally fix this in my code (of the commerce_billy_mail.module).
How I fixed it:
Before I used 'filepath' as key in the $attachments array:
So just went from "filepath" to "filecontent"... which I just found in an older patch and had a trial and error... so please give us a better documentation.
The path is in the temporary folder of the server, because it should not be accessible from outside and is only a temporary invoice PDF created just for emailing.
At least this needs review and documentation work...
Comment #15
AnybodyComment #16
sgabe CreditAttribution: sgabe commented@Anybody: Currently this is mentioned in the documentation of mimemail_prepare_message(). Please make your suggestions and comments to improve this.
Comment #17
paulovg12 CreditAttribution: paulovg12 commented7.x-1.0-beta3 Attachments do not work because of the following codes in mimemail.module the hook:
...
This code expects attachments to be a long string of paths delimited by \n . it conflicts directly with the function
function mimemail_prepare_message($message)
which expects the attachment to be in form of an array of arrays :
* The array of arrays looks something like this:
* Array
* (
* [0] => Array
* (
* [filepath] => '/sites/default/files/attachment.txt'
* [filecontent] => 'My attachment.'
* [filename] => 'attachment.txt'
* [filemime] => 'text/plain'
* )
* )
The updated code also has no chance of working with different mime types (which I need!), I guess there can be some code to declare the mime type based on the file suffix, but it will make the module less flexible. The current format of attachments array of arrays is ok and is working!
I modified the function as follows and it now works perfectly (for my purposes anyway!)
/* $attachments = array();$attachments_string = trim($params['attachments']);
if (!empty($attachments_string)) {
$attachment_lines = array_filter(explode("\n", trim($attachments_string)));
foreach ($attachment_lines as $filepath) {
$attachments[] = array(
'filepath' => trim($filepath),
);
}
}*/
Comment #18
sgabe CreditAttribution: sgabe commentedSomething is terribly wrong there. As I mentioned this in a previous comment.
You should never ever call drupal_mail('mimemail', [..])!
Comment #19
anrikun CreditAttribution: anrikun commentedSame problem as #17 and #18 here.
Comment #20
anrikun CreditAttribution: anrikun commentedComment #21
anrikun CreditAttribution: anrikun commentedHere's a patch that fixes the issue.