# Send scheduled emails with SendGrid

Send scheduled emails through [SendGrid](https://sendgrid.com) from your verified sender: recurring reports, reminders, and digests filled in from any API.

## Example: a daily open-tickets digest

```json
{
  "name": "Open tickets digest",
  "cron": { "expression": "0 7 * * 1-5", "time_zone": "Australia/Sydney" },
  "nodes": [
    { "id": "tickets", "request": { "method": "GET", "endpoint": "https://support.example.com/api/tickets?status=open", "credential_id": "YOUR_HELPDESK_TOKEN_ID" } },
    { "id": "lines", "transform": { "template": "{ \"count\": \"{{ $.tickets.length }}\", \"lines\": { \"{{#each $.tickets}}\": \"#{{ $.id }} {{ $.subject }} ({{ $.priority }})\" } }" } },
    { "id": "email", "sendgrid_send_email": {
        "credential_id": "YOUR_SENDGRID_KEY_ID",
        "from": "support@acme.com",
        "to": "support-team@acme.com",
        "subject": "{{ $.count }} open tickets",
        "text": "{{ join($.lines, \"\\n\") }}" } }
  ]
}
```

## Set up

Verify a sender or domain in SendGrid, create an API key with **Mail Send** access, and save it as a `bearer_token` credential.

## Reference

### Send an email with SendGrid: `sendgrid_send_email`

**Sends** POST `https://api.sendgrid.com/v3/mail/send`. **Output** for the next step: Nothing: SendGrid answers `202` with an empty body.

| Field | Type | Notes |
| --- | --- | --- |
| `credential_id` | string, required | The id of a `bearer_token` credential holding a SendGrid API key (`SG.…`). |
| `from` | string, required | The sender address, on a domain verified with SendGrid. Placeholders allowed. |
| `from_name` | string | Shown with the address, as "Name <from>". Placeholders allowed. |
| `to` | string, required | The recipient address. Placeholders allowed. |
| `subject` | string, required | Up to 998 characters. Placeholders allowed. |
| `text` | string, required | Plain text, up to 40,000 characters. Placeholders allowed. |
