> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kibocommerce.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Email (Embedded Before)

This action occurs before a an email is sent. Changes made to the email's content and subject.  The email can also be suppressed and not sent at all.

<table><tbody><tr><th>Action Type</th><td>[Embedded](/pages/types-of-actions)</td></tr><tr><th>Full Action ID</th><td>embedded.commerce.email.render.before</td></tr><tr><th>Runs multiple custom functions?</th><td>No</td></tr></tbody></table>

## Examples

### Prefix Subject & Conditional Suppression

```
exports.handler = function(context, callback) {
  try {
    const subject = context.items.getSubject;
    const model = context.items.getModel;

    if (subject === 'order.changed' && !model?.items?.length) {
      context.items.exec('suppressEmail');
      return callback();
    }

    context.exec.setSubject('MyBrand ' + subject]);
    callback();
  } catch { callback(); }
};
```

### Dynamic Template Swap & Model Enrichment

```
exports.handler = function(context, callback) {
  try {
    const subject = context.items.getSubject;
    const model = context.items.getModel;

    if (subject === 'order.changed' && model?.isCurbside) {
      context.exec.setTemplate('order.curbside.custom');
      context.exec.setSubject('Your curbside order is confirmed');
    }

    if (model?.items?.length) {
      model.highDuty = model.items.some(i => i.dutyAmount > 100);
      context.exec.setModel(model);
    }
    callback();
  } catch { callback(); }
};
```

### Example injecting dynamic content using model

```
exports.handler = function (context, callback) {
    
    console.log('this is the test for changing the email content dynamically');
        
    // scenario: add custom content to order changed email

    var model = context.items.getModel;
    var user = context.items.getUser;
    var firstName = user.firstName;

    console.log('user first name is ' + firstName);
    console.log('order number is ' + model.orderNumber);
    console.log('email subject is ' + context.items.getSubject);

    var subject = context.items.getSubject;
    
    if (subject == "order.changed") {
        model.customContent = "This is custom content added dynamically through arc for user " + firstName + " for order " + model.orderNumber;
        context.exec.setModel(model);

        var newContent = context.items.getModel;
        console.log('new content is ' + JSON.stringify(newContent, null, 2));
        console.log('set new content successfully');
    }

    callback();
};
```
