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?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

arkestra’s picture

Seconded -- rolling back to alpha2 fixed the issue.

Noticed the issue through integration with mass_contact module.

howdytom’s picture

Yes, 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!

sgabe’s picture

@howdytom: You should update your rules settings as stated in the release note:

Since now it is possible to use custom keys and set the language for messages, be sure to set a unique key for your Rules and system actions and test your custom theme implementations!

howdytom’s picture

Status: Active » Closed (fixed)

@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.

Anybody’s picture

Status: Closed (fixed) » Active

For your information: In our case it is not a rule, but a mail sent from a module.

This is the drupal_mail call:


$params = array(
    'subject' => $subject,
    'body' => $body,
    'plain' => !empty($plaintext),
    'attachments' => $attachments,
    'headers' => array(
      'Cc' => trim(variable_get('commerce_billy_mail_cc', '')),
      'Bcc' => trim(variable_get('commerce_billy_mail_bcc', '')),
    ),
    'context' => array(
      'subject' => $subject,
      'body' => $body,
      'order' => $order,
    ),
  );

drupal_mail('commerce_billy_mail', 'commerce_billy_mimemail_send_order_invoice', $order_account->mail, $order_account_language, $params, $from, $send);

Do you see something wrong there or is it a problem in mimemail?

After the update no more attachments are working, as described initially.

sgabe’s picture

Priority: Critical » Normal

Check the location of your attachments. The files cannot be outside the public files directory just if you enable the "Send arbitrary files" permission.

Anybody’s picture

The 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!

sgabe’s picture

The temporary directory can be set and usually defaults to be inside the public files directory.

Anybody’s picture

I'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.

m1r1k’s picture

@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.

Anybody’s picture

Thank 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.

trentl’s picture

I 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

Anybody’s picture

In my case the file does not contain spaces.

Anybody’s picture

It 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:

// Before (worked in alpha2 but no more in beta1)
$attachments[] = array(
    'filepath' => $pdf_path, //you have to use relative paths.
    'filename' => basename($pdf_path), // can use any alias name here
    'filemime' => 'application/pdf', // mime file type
    'list' => TRUE,
  );
// Works in beta1, not yet testet in alpha2:
$attachments[] = array(
    'filecontent' => $pdf_path, //you have to use relative paths.
    'filename' => basename($pdf_path), // can use any alias name here
    'filemime' => 'application/pdf', // mime file type
    'list' => TRUE,
  );

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...

Anybody’s picture

Issue summary: View changes
Status: Active » Needs work
sgabe’s picture

@Anybody: Currently this is mentioned in the documentation of mimemail_prepare_message(). Please make your suggestions and comments to improve this.

/**
 * Prepares the message for sending.
 *
 * @param array $message
 *   An array containing the message data. The optional parameters are:
 *   - plain: Whether to send the message as plaintext only or HTML. If evaluates to TRUE,
 *     then the message will be sent as plaintext.
 *   - plaintext: Optional plaintext portion of a multipart email.
 *   - attachments: An array of arrays which describe one or more attachments.
 *     Existing files can be added by path, dinamically-generated files
 *     can be added by content. The internal array contains the following elements:
 *      - filepath: Relative Drupal path to an existing file (filecontent is NULL).
 *      - filecontent: The actual content of the file (filepath is NULL).
 *      - filename: The filename of the file.
 *      - filemime: The MIME type of the file.
 *      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'
 *        )
 *      )
 *
 * @return array
 *   All details of the message.
 */
function mimemail_prepare_message($message) {
  [...]
paulovg12’s picture

7.x-1.0-beta3 Attachments do not work because of the following codes in mimemail.module the hook:
...

      function mimemail_mail($key, &$message, $params) {
  $context = $params['context'];
  $options = array('clear' => TRUE);

  // Prepare the array of the attachments.
   $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),
      );
    }
  }

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!)

function mimemail_mail($key, &$message, $params) {
  $context = $params['context'];
  $options = array('clear' => TRUE);

  // Prepare the array of the attachments.
  $attachments = $params['attachments'];

/* $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),
);
}
}*/

sgabe’s picture

Status: Needs work » Active

Something is terribly wrong there. As I mentioned this in a previous comment.

[...] the hook_mail() implementation in the module considers file attachments as a multiline string because it handles messages sent via Rules actions provided by MimeMail itself. For more information see drupal_mail().

You should never ever call drupal_mail('mimemail', [..])!

anrikun’s picture

Same problem as #17 and #18 here.

anrikun’s picture

Version: 7.x-1.0-beta1 » 7.x-1.x-dev
anrikun’s picture

Status: Active » Needs review
FileSize
1.13 KB

Here's a patch that fixes the issue.