# Send emails with Zapier

> Send from a Zap with SMTP by Zapier.

## What you'll build

A Zap that sends email through PostShiba with the **SMTP by Zapier** app's **Send Email** action. You can also send with the REST API from Webhooks by Zapier, and start Zaps from PostShiba delivery events.

## Before you start

- An SMTP username and password. Open your cluster in the dashboard, go to its SMTP credentials, and choose **Create SMTP credential**. Copy the password right away, because it is shown once. You can also use the [SMTP credentials API](/docs/api-reference/smtp-credentials).
- A verified sending domain. See [Add and verify a domain](/docs/add-a-domain). The From address must be on it.
- A **Transactional** cluster that is ready to send. One-off notifications from a Zap belong on a transactional cluster, and the type is locked after create. See [Clusters](/docs/dashboard/clusters/introduction).

## Install

Nothing to install. SMTP by Zapier and Webhooks by Zapier are built into Zapier.

## Send your first email

1. In the Zap editor, add an action step, search for **SMTP**, and set **Action event** to **Send Email**.
2. Click **Sign In**. In the window that opens, enter these values and click **Yes, Continue to SMTP by Zapier**.

```text zapier-smtp.txt
Host:        smtp.postshiba.com
Username:    smtp_9
Password:    YOUR_PASSWORD
Use TLS:     Yes
Port:        587
From Email:  hello@mail.example.com
```

3. In the action, set **From Email** to an address on your verified domain. Fill in **To**, **Subject**, and the body. **To** takes up to five addresses. If you fill in **HTML Body**, also give a plain-text body.
4. Click **Test step**. The test sends a real email, and it shows under Events in the dashboard.

Zapier's **Use TLS** connects with STARTTLS, which is what PostShiba offers on port `587`. Do not pick port `465`. PostShiba does not offer it, and Zapier does not support implicit TLS there either. Every SMTP setting is on [Send emails with SMTP](/docs/send-with-smtp).

## Send with the API instead

The REST API returns the message id and JSON errors. Use **Webhooks by Zapier**, which is a premium app, so it needs a paid Zapier plan. You also need an API key with **Full access**. See [Create an API key](/docs/create-an-api-key).

1. Add an action step with **Webhooks by Zapier** and set **Action event** to **Custom Request**.
2. Fill in these fields. Under **Headers**, enter each header name on the left and its value on the right.

```text zapier-webhook.txt
Method:   POST
URL:      https://app.postshiba.com/api/v1/emails
Data:     {"from": "hello@mail.example.com", "to": "you@example.com", "subject": "Your receipt", "text": "Thanks for your order."}
Headers:  Authorization  Bearer YOUR_API_KEY
          Content-Type   application/json
```

3. Click **Test step**. A queued send returns `201` with `"queued": true`.

Custom Request sends **Data** exactly as you typed it. If you map a value that contains a quote or a line break into the JSON, the body is no longer valid JSON and PostShiba refuses it. `to` takes one address or a comma-separated string. Every field is on [Send emails with HTTP](/docs/send-with-http).

## React to delivery events

PostShiba POSTs each delivery event to a URL as a JSON array in the SendGrid Event Webhook format. Each request carries one event, and Zapier runs the Zap once for each object in the array.

1. Start a Zap with **Webhooks by Zapier** and set **Event** to **Catch Hook**. Click **Continue**, then copy the webhook URL from the **Test** tab.
2. In PostShiba, open **Webhooks**, click **Add endpoint**, paste the URL, and save. See [Managing webhooks](/docs/webhooks/introduction).
3. Click **Send test event** on the endpoint in PostShiba, then click **Test trigger** in Zapier. The test event has `"test": true`.
4. Map fields such as `event`, `email`, and `sg_event_id` in later steps. Fields on each event are on [Event types](/docs/webhooks/event-types).

Catch Hook parses the body, so it can't check the `X-Capsule-Signature` header, which is computed over the raw body. Anyone who has the webhook URL can start the Zap, so keep it private. To check signatures, use **Catch Raw Hook**, which passes the unparsed body and the headers, and follow [Verify webhook requests](/docs/webhooks/verify-webhooks-requests) in a later step.

## Troubleshooting

When the cluster reaches its hourly throttle or 24-hour cap, SMTP answers `451 4.7.0 hourly send limit reached` or `451 4.7.0 daily send limit reached`, and the API answers `429` `throttled`. The message is not kept. Retry once the cap has room. See [What happens at your cap](/docs/dashboard/clusters/what-happens-at-your-cap).

| What you see | What to do |
| --- | --- |
| The SMTP connection fails | Check the username and password. Set **Use TLS** to **Yes** and **Port** to `587`. PostShiba accepts `AUTH PLAIN` only. After repeated wrong passwords, logins fail with `454 4.7.0 too many failed logins, try again later` for a while. |
| `550 unverified domain` or `550 from header not aligned with verified domain` | Set **From Email** in the action to an address on your verified domain. |
| `550 domain_suspended` or `403` `domain_suspended` | The From domain is paused. Resume it from [Managing domains](/docs/dashboard/domains/manage-domains). |
| `550 kyc_required` or `403` `kyc_required` | Your team is pending production approval. Until then, send only to team members, live inbox addresses, and inbox forward-to addresses. See [Does PostShiba require production approval?](/docs/knowledge-base/does-capsule-require-production-approval) |
| `550 suppressed` or `550 firewall: <rule>` | The recipient is on the [suppression list](/docs/dashboard/emails/email-suppressions) or failed an [email firewall](/docs/dashboard/emails/email-firewall) check. |
| `401` `Invalid token or no user signed in` | The `Authorization` header must be `Bearer ` followed by a Full access API key. |
| `422` `invalid` | `field` names the problem. Check that **Data** is valid JSON after Zapier fills in mapped values. |
| The webhook endpoint in PostShiba shows **Retrying** or **Down** | Zapier returns `404` when the Zap is off or deleted. Turn the Zap on. See [Managing webhooks](/docs/webhooks/introduction). |

## Next steps

- [Send emails with SMTP](/docs/send-with-smtp) for every setting and reply.
- [Send emails with HTTP](/docs/send-with-http) for every field on the send request.
- [AUTH PLAIN, not AUTH LOGIN](/docs/knowledge-base/auth-plain)
- [Event types](/docs/webhooks/event-types)
