Skip to content

Conversation

@dgorbash
Copy link

Summary

  1. Add support for functions/Promises in forwardMapping recipients list.
    For example:
{
  ...
  forwardMapping: {
    "info@example.com": [
      Promise.resolve("jim@example.com"),
      () => Promise.resolve("jane@example.com"),
      data => {
         // do some stuff
         return "bob@example.com";
      }
    ]
  },
  ...
}
  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: {
    "info@example.com": [
      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 'junk@example.com';
        } else {
          return 'office@example.com';
        }
      }
    ]
  }
}
  1. Check for custom header and stop forwarding if check fails:
{
  ...
  skipRejectedRecipients: false,
  forwardMapping: {
    "info@example.com": [
      'office@example.com',
      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: {
    "info@example.com": [
      'office@example.com',
      () => {
        // If returned Promise will be rejected due to errors, message will be forwarded to office@example.com only
        return MyAwesomeApi.getEmails() // example response: jane@example.com, bob@example.com
          .then(list => {
            // It is ok to return array of email addresses
            return list.split(/\s*,\s*/); // output: [ "jane@example.com", "bob@example.com" ]
          })
      }
    ]
  }
}

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