Redirect emails declared in Mandrill template data to a single developer's/QA's email. Useful during development and testing.
E.g. Given two recipients [email protected], [email protected] and a redirect email of [email protected] the resulting recipients will be [email protected] and [email protected].
##Use
Install via npm install mandrill-redirect
and use:
var redirect = require('mandrill-redirect');
redirect(template, "[email protected]"); // Returns true/false
rewrites a Mandrill template:
{
message:{
to: ["[email protected]", "[email protected]"],
merge_vars: [
{
rcpt: "[email protected]",
vars: [...]
},
{
rcpt: "[email protected]",
vars: [...]
}
],
recipient_metadata:[
{
"rcpt": "[email protected]",
"values": [...]
},
{
"rcpt": "[email protected]",
"values": [...]
}
]
}
}
to:
{
message: {
to: ["[email protected]", "[email protected]"],
merge_vars: [
{
rcpt: "[email protected]",
vars: [...]
},
{
rcpt: "[email protected]",
vars: [...]
}
],
recipient_metadata:[
{
"rcpt": "[email protected]",
"values": [...]
},
{
"rcpt": "[email protected]",
"values": [...]
}
]
}
}
Also:
- to is mandatory and must have length
- merge_vars is optional but if provided must match the length of to
- recipient_metadata is optional but if provided must match the length of to
- If no email is given for redirecting then any template manipulation is skipped.
- The return value is true/false indicating success/failure. The template is rewritten in place.