Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I have an image with a substitution tag in a SendGrid template?

I am creating a template in SendGrid and I was trying to put an image in the center, and the URL I would like to be a tag so I can substitute dynamically in my code, because it will come from my database.

I tried to simply place a tag in the input field, but it doesn't accept that. Is there a way I can accomplish that?

Thank you!

like image 217
Denis Cappelini Avatar asked Dec 16 '16 02:12

Denis Cappelini


1 Answers

I assume that you have managed to trigger the SendGrid API via Node.js, since you're tagging the question with the Express tag.

I'm currently trying to build transactional email template using SendGrid as well, and I managed to accomplish this.

You'd probably want to add a new image element first using the builder.

add an image

Then upload an image. Once your image is uploaded, double click on the image element. Grab the name of your image file and copy it.

image file

Switch over to the code view.

code view

In the code view, find the html tag that contains your name of your image file. Here's an example in my case.

code to replace

Replace this code with your "substitution tag".

substitution tag

Save the template. Your template should be ready to use. In your Node.js code, set the substitution tag.

mail.personalizations[0].addSubstitution(new helper.Substitution("your-subtitution-tag", "image-url"));

I used this library: https://github.com/sendgrid/sendgrid-nodejs Hopefully your email should contain the new image.

email result

I blurred out some sensitive contents above. This is the email result on my end. Hope this helps!

like image 70
Nicholas Lie Avatar answered Sep 19 '22 14:09

Nicholas Lie