Skip to content
Software capabilities
Twilio SendGrid

Send a transactional email with a SendGrid template

Send a dynamic transactional template through Mail Send. Call the v3 API directly or use SendGrid’s Node.js SDK.

Documentation reviewed · 2 methods with sources

Ways to do it

  1. API: POST /v3/mail/send
  2. SDK: sgMail.send(message)
API

POST /v3/mail/send

Send a message using a dynamic template ID and personalization data.

Read source: SendGrid Mail Send API reference
Requirements
A SendGrid API key with Mail Send permission, a verified sender, a recipient, and an active dynamic template ID beginning with d-.
Limitations
A successful 202 response means SendGrid accepted the request. It does not confirm delivery to the recipient’s inbox. One request supports at most 1,000 personalizations.

Example shell

curl --fail -X POST https://api.sendgrid.com/v3/mail/send \
  -H "Authorization: Bearer $SENDGRID_API_KEY" -H "Content-Type: application/json" \
  -d '{"from":{"email":"verified@example.com"},"personalizations":[{"to":[{"email":"recipient@example.com"}],"dynamic_template_data":{"name":"Alex"}}],"template_id":"d-template-id"}'
SDK

sgMail.send(message)

Submit a dynamic template email from a Node.js application with the SendGrid Mail SDK.

Read source: SendGrid Node.js Email API quickstart
Requirements
Node.js, the @sendgrid/mail package, an API key with Mail Send permission, and a verified sender and dynamic template.
Limitations
The SDK submits through the same Mail Send API. A successful request does not establish that the email reached the inbox.

Example text

sgMail.setApiKey(process.env.SENDGRID_API_KEY);
await sgMail.send({ to, from, templateId, dynamicTemplateData });