Answers.Body: <p>I suppose you could use the <code>\craft\commerce\services\Emails::EVENT_BEFORE_SEND_MAIL</code> event for that.</p>
  
  <pre class="lang-php prettyprint-override"><code>use craft\commerce\events\MailEvent;
  use craft\commerce\services\Emails;
  use yii\base\Event;
  
  Event::on(
      Emails::class,
      Emails::EVENT_BEFORE_SEND_MAIL,
      function (MailEvent $e) {
          // You would be able to access the `\craft\mail\Message` like so
          // $e-&gt;craftEmail;
  
          // And the `\craft\commerce\elements\Order` like so
          // $e-&gt;order
  
          // So adding an asset could be done by accessing the `attach` method.
          // https://www.yiiframework.com/extension/yiisoft/yii2-swiftmailer/doc/api/2.1/yii-swiftmailer-message#attach()-detail
          $e-&gt;craftEmail-&gt;attach(...);
      }
  );
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-04T19:28:53.033Z
Answers.LastActivityDate: 2019-03-07T14:35:04.730Z
Answers.LastEditDate: 2019-03-07T14:35:04.730Z
Answers.UserDisplayName: Maarten de Graaf
Body: <p>Suppose I have an assets field in my orders fields, how could I attach those files in the confirmation email?</p>
  
Tags: <plugin-craftcommerce><emails>
Title: Add attachments with Craft Commerce
ThreadText: # Add attachments with Craft Commerce
  
  (Asked by: username_0 on 2019-03-04)
  
  Suppose I have an assets field in my orders fields, how could I attach those files in the confirmation email?
  
  **Tags:** plugin-craftcommerce, emails
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-03-04. Score: 1
  
  I suppose you could use the `\craft\commerce\services\Emails::EVENT_BEFORE_SEND_MAIL` event for that.
  
  ```php
  use craft\commerce\events\MailEvent;
  use craft\commerce\services\Emails;
  use yii\base\Event;
  
  Event::on(
      Emails::class,
      Emails::EVENT_BEFORE_SEND_MAIL,
      function (MailEvent $e) {
          // You would be able to access the `\craft\mail\Message` like so
          // $e->craftEmail;
  
          // And the `\craft\commerce\elements\Order` like so
          // $e->order
  
          // So adding an asset could be done by accessing the `attach` method.
          // https://www.yiiframework.com/extension/yiisoft/yii2-swiftmailer/doc/api/2.1/yii-swiftmailer-message#attach()-detail
          $e->craftEmail->attach(...);
      }
  );
  
  ```
  
  
  ---
  
  