Skip to content

Conversation

dgorbash
Copy link

Summary

  1. Add support for functions/Promises in forwardMapping recipients list.
    For example:
{
  ...
  forwardMapping: {
    "[email protected]": [
      Promise.resolve("[email protected]"),
      () => Promise.resolve("[email protected]"),
      data => {
         // do some stuff
         return "[email protected]";
      }
    ]
  },
  ...
}
  1. New config option skipRejectedRecipients (boolean). If true all rejected promises in forwardMapping will be silently ignored. If false (by default) any rejected promise will cancel forwarding (may be used for validation).

Examples

  1. Validate incoming emails and send junk messages into a separate mailbox:
{
  ...
  forwardMapping: {
    "[email protected]": [
      data => {
        let dataReceipt = data.event.Records[0].ses.receipt;
        if (dataReceipt.spamVerdict.status !== 'PASS' ||
            dataReceipt.dkimVerdict.status !== 'PASS' ||
            dataReceipt.spfVerdict.status !== 'PASS' ||
            dataReceipt.virusVerdict.status !== 'PASS') {  
          return '[email protected]';
        } else {
          return '[email protected]';
        }
      }
    ]
  }
}
  1. Check for custom header and stop forwarding if check fails:
{
  ...
  skipRejectedRecipients: false,
  forwardMapping: {
    "[email protected]": [
      '[email protected]',
      data => {
        let headers = data.event.Records[0].ses.mail.headers;
        let header = headers.find(h => h.name === 'X-MyCompany-Signature');
        if (!header || header.value !== 'VALID-SIGNATURE') {  
          return Promise.reject('Invalid signature');
        }
        // Empty values will be ignored so return nothing
      }
    ]
  }
}
  1. Get list of recipients from remote source:
{
  ...
  skipRejectedRecipients: true,
  forwardMapping: {
    "[email protected]": [
      '[email protected]',
      () => {
        // If returned Promise will be rejected due to errors, message will be forwarded to [email protected] only
        return MyAwesomeApi.getEmails() // example response: [email protected], [email protected]
          .then(list => {
            // It is ok to return array of email addresses
            return list.split(/\s*,\s*/); // output: [ "[email protected]", "[email protected]" ]
          })
      }
    ]
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant