Attaching files in Drupal Commerce Selling files online with the following pieces:

Commerce 7.x-1.8
Commerce File 7.x-1.0
Mime Email 7.x-1.0-beta3

I would like to provide people with a document attached to an email. The commerce-checkout-rules almost gets there. What is the token replacement that 'provides a list of files; one per line'? Or otherwise, how do we attach the files being checked out?
Resolved it. 

The trick was to create a new variable in the rule. 


Store > Configuration > Checkout Settings > Checkout Rules.  
Edit the rule : Send an order notification email.
Create a loop over each commerce-order:commerce-line-items.
Add a variable to the loop.


This was the trick. 

The data selector is: list-item:commerce-file-line-item-files:0:file

Don't worry about the the 0 - the loop is sending 1 email per document. The result could be cumbersome, but means that if people order 20 documents and they are large, they should still get through.  

I called the variable: added_commerce_file_licence_items.

6) Create a Send HTML e-mail rule. Put it in the loop.

The attachments field contains: 

[added-commerce-file-licence-items:path]

7) Make sure that the permission "Send arbitrary files" is set. 

I could also send by hook_mail_alter(&amp;$message), which allowed me to try a few different things such as permutations of the URL and get a working version without too much experimentation. 

function commerceemaildoc_mail_alter(&amp;$message) {     
  if (array_key_exists('attachments', $message['params'])) {
    foreach ($message['params']['attachments'] as $attachment) {
        $file_content = file_get_contents($attachment['filepath']);
        $mime_type = file_get_mimetype($attachment['filepath']);
        $attachment = array(
            'filecontent' =&gt; $file_content,
            'filename' =&gt; basename($attachment['filepath']),
            'filemime' =&gt; $mime_type,
        );
        $message['params']['attachments'][] = $attachment;
    }
  }
}