aws-lambda-ses-forwarder
aws-lambda-ses-forwarder copied to clipboard
Support for dynamic list of recipients
Summary
- 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]";
}
]
},
...
}
- New config option
skipRejectedRecipients
(boolean). Iftrue
all rejected promises inforwardMapping
will be silently ignored. Iffalse
(by default) any rejected promise will cancel forwarding (may be used for validation).
Examples
- 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]';
}
}
]
}
}
- 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
}
]
}
}
- 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]" ]
})
}
]
}
}