Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send multiple dynamic emails through Sendgrid

I would like to know if it's possible to send multiple dynamic emails using Sendgrid's SMTP-API.

I know it is possible to send one email body to several recipients, passing user data through substitutions, but what if the email body is different for each user?

Imagine you send an email to one user with an image1.jpeg and then an email with image2.jpeg, image3.jpeg and image4.jpeg to a different user.

Basically, I want to be able to send multiple emails with dynamic content per user.

Is this possible with Rails? Or Java?

Thanks.

like image 646
Luis Martins Avatar asked Aug 17 '26 00:08

Luis Martins


1 Answers

Use the Template Engine.

Create a template via the UI at https://sendgrid.com/templates or via the API.

Then enable the "templates" filter in your X-SMTPAPI header with the template of the id you create:

{
  "filters": {
    "templates": {
      "settings": {
        "enable": 1,
        "template_id": "5997fcf6-2b9f-484d-acd5-7e9a99f0dc1f"
      }
    }
  }
}

Then you'll use the SMTP API substitutions and sections for your dynamic content. There's an example combining this with template engine templates.

like image 73
bwest Avatar answered Aug 18 '26 18:08

bwest