Adding parameters to emails

Hi there!

I know that Filip talks about email body being html and can be coded as such, however I am a bit challenged. I have switched to admin cli (like that much better, thank you) and decided to get a bit fancier with my emails, like adding user name to it and breaking it down into paragraphs and such. I kept getting errors thrown whenever I did anything but one line, double quotes and words.

I tried "Hello " + name + “!” as well as Hello ${name}! (of course after identifying the variable) but all of those throw an error. So I figured I ask if there is another way to do this or it’s just not a functionality at the moment.

Much thanks!

1 Like

Did you try {{name}} ? it says something about that on the sendgrid documentation. I’m not sure if you are using sendgrid or not, though.

1 Like

Hey @nev

Please take a look at this post and if you find any solution to your issue in any of the first 3 Steps:

If this doesn’t help, please follow Step 4 and share more details about your issue here, so we can help you with your issue as quickly as possible.

Basically any time anything other than text is added in html part of the email, the email does not send. I likely did not explain that correctly.

The only thing that I have found that works for the email to send it just plain text, like:

html: "Hello and thank you for signing up!"

If I try things like:

html: "<h1> Hello and welcome!</h1> <br> <p>So excited you are here....</p>"

The email does not send. So, what I was inquiring about is what solutions, if any, are there for the html (body) part of the email to work like html where it can be more than just a seamless line of text.

Perhaps that explains what I’m after a bit better.

TL;DR: just follow this full tutorial and you will be sending html emails using Moralis and Sendgrid:

Instead of sending html, I build a template on sendgrid with the html I wish to send, and add {{variable_name}} in the parts I wish to make dynamic.

Here is how I did it. First, as per described in minute 4:16 you create the cloud function.

Then if you go to Sendgrid, you create a new Dynamic Template (set the id in the cloud function) as per the tutorial on about at minute 5:57, then you click on “Add Version” , then create a “Blank Template”, you add the “Subject” to the email, then on the top you choose Build, and you can build your email kind of like a WYSIWYG style editor where you can drop modules like images, text boxes, etc (if you have created pages on wordpress, this is very similar). If you have specific html, there is a code view to edit the template.

When you are done, and ready to send the email from moralis app, you call your cloud function with something like this:

const sendEmail = async() => {
   await"confirmationEmail", {email:'[email protected]', first_name:"Josh"})   

I hope that helps.

1 Like

I would advice you to use sendgrid transactional templates. And insert sendgrid handlebars like {{ firstname }}. Then you can pass in that data into the sendEmail function as dynamic_template_data.

1 Like

@filip @krb thank you! this is perfect and it works like a charm. Exactly what I was looking for!!!

1 Like