'Mandrill Reply-To Header when sending via Node.js
I am trying to figure out how to add a reply-to header to emails sent from my website using mandrill transactional API. I have tried multiple options but none is working. I want to implement a contact us form and send emails from my domain to support email where they can easily reply back to users.
{
"key":"xxxxxxx",
"template_name": "welcome-email",
"template_content":{},
"message": {
"merge" : true,
"global_merge_vars" : [ {
"name" : "my_h_tag",
"content" : "THIS IS WORKING"
}],
"merge_vars": [],
"merge_language": "handlebars",
"async" : false,
"subject":"Testing Revamp Api",
"from_email":"hello@mydomain",
"to":[
{
"email":"user email",
"type":"to"
}
],
"headers":[
{
"reply_to":"user email eneterd in contact form"
}
]
}
}
Thanks in Advance.
Solution 1:[1]
Your general approach is correct, passing Reply-To via headers should be supported, but the header is called reply-to (with the dash), while you use an underscore. Have you tried to use the dash?
Also, per documentation, headers should be an object.
{
"key": "xxxxxxx",
// ...
"message": {
// ...
"headers": {
"reply-to": "user email eneterd in contact form"
}
}
}
Related: Mandrill Reply-to
Solution 2:[2]
Quick solution:
(async () => {
const dir = "./public/page-data/blog";
const fileRegex = /.*/;
const allFiles = findInDir(dir, fileRegex);
try {
await Promise.all(
allFiles.map((file) => {
return new Promise((resolve, reject) => {
fs.readFile(file, "utf8", (err, data) => {
const obj = JSON.parse(data);
if (obj.result.pageContext.featured === true) {
reject("Inside item, looking for featured prop");
} else {
resolve();
}
});
});
})
);
} catch (err) {
throw new Error("There are multiple featured blog posts, please fix.");
}
})();
Instead of checking every item one by one like in an loop i do it like this. It checks "parallel" if any of them has featured set to true. Therefore its faster then a loop
If its true i reject it and the Promise.all() stops. The try / catch of the Promise.all() catches the rejection
You need to understand just 1 thing to know when to use await and when not.
It only makes sense to use await on promises.
How do you know if its an promise? Just console.log it
Does it console log Promise? Use await
Does it NOT console log Promise? It makes no sense to use await
This returns just an array. Does it makes sense to use await? No, it does not return an Promise
But if you do it like this:
You have an array of promises.
Here is a bit different. You have an array BUT the elements inside are an promise.
You can use Promise.all() it basically awaits for every item in the array until its done.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | bill.gates |


