Send an email with SendGrid
To send an email from a workflow through your own SendGrid account, save a SendGrid API key as an API connection and call SendGrid’s mail send endpoint from an HTTP request block. Every run that reaches the block sends one email from an address you have verified with SendGrid.
You need a SendGrid account, the member role or higher in the OutWin workspace, and edit access to the workflow’s project. The SendGrid steps happen in SendGrid’s own console at app.sendgrid.com. The Twilio Console at console.twilio.com is a separate site and has no Sender Authentication page.
Verify a sender in SendGrid
Section titled “Verify a sender in SendGrid”SendGrid sends mail only from an address or a domain you have verified.
- In the SendGrid console, open Settings, then Sender Authentication.
- Under Single Sender Verification, select Verify a Single Sender.
- Fill in the Create a Sender panel and select Create.
- Open the email SendGrid sends to that address and select the link in it.
A single sender is enough to start. For production mail, authenticate your whole domain under Domain Authentication on the same page. A sender address at a free provider such as gmail.com draws a “not recommended” warning. It still works, and its mail may land in spam.
Create a SendGrid API key
Section titled “Create a SendGrid API key”- In the SendGrid console, open Settings, then API Keys, and select Create API Key.
- Enter a name for the key.
- Choose Custom Access and give Mail Send full access. Leave every other permission off.
- Select Create & View and copy the key.
SendGrid shows the key once. It starts with SG..
Add the SendGrid connection
Section titled “Add the SendGrid connection”- In OutWin, open Connections and select Add API connection.
- In Name, enter
SendGrid. - In Base URL, enter
https://api.sendgrid.com. For an EU-region SendGrid account, enterhttps://api.eu.sendgrid.com. - Under Authentication, keep Bearer token and paste the key into Token.
- Select Add connection.
After you save, nobody can read the key back. It can only be replaced, and every role sees a masked hint in its place. Members can add and edit a connection, and only owners and admins can delete one. Connect an API covers the other fields and how to replace a key.
Add the HTTP request block
Section titled “Add the HTTP request block”-
In the workflow, add an HTTP request block. The block palette lists it in the API group.
-
Under Connection, choose SendGrid.
-
Under Request, keep
POSTand enter the path/v3/mail/send. -
Under Body, choose JSON and enter this body:
{"personalizations": [{ "to": [{ "email": "{{input.email}}" }] }],"from": { "email": "you@example.com" },"subject": "Welcome, {{input.name}}","content": [{ "type": "text/plain", "value": "Thanks for signing up on {{today}}." }]} -
Replace
you@example.comwith the sender you verified. SendGrid rejects any other from address.
The card now reads POST /v3/mail/send · SendGrid.
Each expression in the body sits inside quotes, so its value is inserted as text and escaped for JSON. {{input.email}} and {{input.name}} read the email and name fields of what the block receives. Change them to match what the preceding block passes on. The HTTP request reference lists the expressions a body can hold.
Do not add an Authorization header to the block. The connection adds it to every request, and a workflow whose block sets that header cannot be published.
Publish and check the send
Section titled “Publish and check the send”Every run that reaches the block sends a real email, so use a recipient address you own for the first run.
Publish the workflow and start a run. When SendGrid accepts the message, it answers 202 with an empty body, and the block’s line in the run log reads SendGrid answered 202 · POST /v3/mail/send. A 202 means SendGrid accepted the message. It does not mean the message was delivered. To see delivery, open the Activity page in the SendGrid console. A separate workflow can start from SendGrid’s events, such as delivered, bounce, and open, through a Webhook block whose Source is SendGrid. Each event starts its own run. Start a workflow from SendGrid events has the steps, and Webhook settings lists the block’s settings.
SendGrid returns an id for the message in the x-message-id response header. The block directly after reads it as {{input.response.headers["x-message-id"]}}. A block further along reads it as {{steps["Send email"].response.headers["x-message-id"]}}, where Send email is the name of the HTTP request block.
If the send fails
Section titled “If the send fails”When SendGrid answers with an error status, the run shows as Errored. The block’s message reads SendGrid answered 403., with the status SendGrid returned, and the inspector shows what SendGrid said.
| What you see | Cause | Fix |
|---|---|---|
403 with “The from address does not match a verified Sender Identity.” |
The from address in the body is not the sender you verified, or the link in the verification email was never selected. | Set the from address to the verified sender, or finish the verification in SendGrid. |
401 |
The key is wrong, was deleted in SendGrid, or lacks Mail Send access. | Create a key with Mail Send access and replace the token on the connection’s page. You do not republish the workflow. |
A request that was sent is charged even when SendGrid answers with an error. What it costs says which failures add no charge. OutWin does not retry the request, so after you fix the cause, start a new run.