Here it is explained how to specify these properties when sending inline content, but when sending a stored template it is said that they are forbidden.
I tried to send an email by specifying the ID of the template and also the forbidden properties: reply_to
, from.name
and from.email
, and the forbidden properties were ignored.
I see setting the Reply-To header as something normal, not unusual, when sending a transactional email, and I find it strange that I cannot do this when sending a stored template. Setting the From name and email from code and not from the SparkPost template editor also seems a good functionality to have.
My code looks like this (it uses the SparkPost NodeJS API and the emails with their substitution data are successfully sent with this code so the problem is not in the substitution_data
, recipients
or in the callback parts of this code):
client.transmissions.send({
transmissionBody: {
content: {
template_id: 'my-first-email',
reply_to: '[email protected]', // example email address
from: {
name: 'My Name',
email: '[email protected]'
}
},
substitution_data: { /* ... */ },
recipients: [ /* ... */ ]
}
}, function (err, res) { /* ... */ });
Update: I found this question in the SparkPost Support Center but it does not help me.
Update 2: I also found this support question which may help a little but I still need a way to set the Reply-To
header and I am not sure yet if the From
email address (not the From
name, about which I am sure from the linked article that it can do this) can use dynamic substitution data.
Update 3: I sent an email to SparkPost Support and received the following answer:
The Product Manager relayed that we do not have a time frame of when this feature will be in the product. Please keep an eye on our website and slack channel for updates.
As I have tested and accepted an answer for this question, I think they did not understand me well. But it is a happy end, after all.
If you specify template_id
, you can't specify any other options in the content
object. So if you want to customize the template, you'll need to add substitution variables in your template.
One thing to note is that if you use substitution variables in your From:
header, that will mean you cannot edit that template using the UI, since there is a hard requirement (in the UI) that you use a verified sending domain.
As Dave Gray mentions above, you can use substitution variables in your template to set custom 'From name', 'From email' and 'Reply-To' fields.
Here's an example template showing how that looks:
{
"content": {
"from": {
"name": "{{fromName}}",
"email": "{{fromEmail}}"
},
"subject": "{{subject}}",
"html": "Hi! I am an HTML part.",
"text": "I am a text part.",
"reply_to": "{{replyTo}}"
}
}
As Dave also points out, you'll need to use the API to update your stored template with these fields. Here's a gist with some JS to do that.
Then you can set fromName
, fromEmail
and replyTo
in your transmission:
{
"recipients": [
"..."
],
"content": {
"template_id": "your-dynamic-template"
},
"substitution_data": {
"fromName": "Your Name",
"fromEmail": "[email protected]",
"replyTo": "[email protected]"
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With