5

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: 'example@sparkpostbox.com', // example email address
            from: {
                name: 'My Name',
                email: 'example2@sparkpostbox.com'
            }
        },
        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.

silviubogan
  • 3,343
  • 3
  • 31
  • 57
  • Please explain to me why you downvoted my question so I can improve it or post another question. – silviubogan Apr 15 '16 at 15:45
  • 1
    Only guessing here: Because you did neither include your current attempt as an actual code block nor verbatim error messages. For an outsider it's always easier to see what you are talking about when you explain actual code than when you just explain. And for a future visitor it's easier to find the question though search when has a bit more beef to it. – Tomalak Apr 18 '16 at 17:34
  • Thank you for the Feedback. Now I added my source code to the question. `:-)` – silviubogan Apr 18 '16 at 19:36

2 Answers2

3

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.

Dave Gray
  • 715
  • 5
  • 11
2

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": "you@yourdomain.com",
    "replyTo": "youagain@yourotherdomain.com"
  }
}
Ewan Dennis
  • 396
  • 1
  • 3
  • I have tested your gist and it looks like in the SparkPost template editor the From Name and From Email values are not updated, and the Reply To value was never visible. I was not aware that someone can change these properties of a template using the API. Thank you! `:-)` – silviubogan Apr 28 '16 at 18:03