---
"@context": https://schema.org
"@type": TechArticle
"@id": https://www.twilio.com/docs/sendgrid/for-developers/sending-email/zapier-sending-for-postgre-sql-row-matches#article
headline: Sending SendGrid Emails For New PostgreSQL Custom Query Row Matches
description: Learn how to use Zapier to send mail through SendGrid when new PostgreSQL rows are created.
url: https://www.twilio.com/docs/sendgrid/for-developers/sending-email/zapier-sending-for-postgre-sql-row-matches
inLanguage: en
dateModified: 2026-07-23T16:57:51.000Z
author:
  "@type": Organization
  name: Twilio Developer Education Team
publisher:
  "@type": Organization
  name: Twilio
---

# Sending SendGrid Emails For New PostgreSQL Custom Query Row Matches

If you want to send emails automatically through SendGrid when new custom PostgreSQL rows are created, you can do that using [Zapier](https://zapier.com).

You will need:

* a [PostgreSQL](https://www.postgresql.com) account
* a [SendGrid](https://sendgrid.com) account
* a [Zapier](https://zapier.com) account

## Steps

1. [Getting your accounts ready](#ready)
2. [Connecting your accounts](#connect)

### Getting your accounts ready \[#ready]

* To connect your PostgreSQL account to Zapier, you need an active PostgreSQL database to pull data from.
* To install PostgreSQL and create a database, see the [PostgreSQL tutorial](https://www.postgresql.org/docs/9.4/static/tutorial-start.html).
* To learn more, see [how to get started with PostgreSQL on Zapier](https://zapier.com/help/postgresql/#how-get-started-postgresql).

To link your PostgreSQL database to Twilio SendGrid, you must have an active Twilio SendGrid account. To learn more, see the [Twilio SendGrid API reference](/docs/sendgrid/api-reference/) and [how to get started with Twilio SendGrid on Zapier](https://zapier.com/help/sendgrid/#how-get-started-sendgrid).

### Connecting your accounts \[#connect]

To begin, open the [Send SendGrid emails for new PostgreSQL custom query row matches](https://zapier.com/zapbook/zaps/4781/send-sendgrid-emails-for-new-postgresql-custom-query-row-matches/) Zap.

1. Choose your PostgreSQL account from the list of accounts, or connect a new account.
2. To connect a new account, you will need the IP address or hostname of where your database is. Input this data in the **Host** field, indicate if you use an alternate **Port**, and fill in the **Database** and **Username** fields with the appropriate data. You may also need to fill out the **Password** field if your database user requires it.

![Form fields for PostgreSQL connection including host, port, database, schema, and username.](https://docs-resources.prod.twilio.com/ddbfbfc81ffd62bdcfb01b49d07053f056333a8d1111dec99fb55de091472a12.png)

3. Create or fill in the **Custom Query** you wish to use. Click **Save + Continue**.

![PostgreSQL New Row Custom Query input field.](https://docs-resources.prod.twilio.com/64a057b50c2607a474571e25519b65ce641b2a25c0a5007370a8bca9a835c07f.png)

4. Choose your SendGrid account from the list of accounts, or connect a new account.
5. To connect your Twilio SendGrid account to Zapier for the first time, enter your API key. If you haven't created an API key, go to the [**API Keys** page](https://app.sendgrid.com/settings/api_keys) in the Twilio SendGrid Console.
6. Using fields from PostgreSQL, create and customize the email message that the Zap will send. The required fields for this step are **To**, **From**, and **Subject**, but you may fill in further fields if you desire to do so.

![Email creation form with fields for To, From, Subject, and Text.](https://docs-resources.prod.twilio.com/3f37d0ccf092d64d9e08da035aeb7f9b8d010dd3425faef4e88deffbbd5009fe.png)

7. Click **Save + Finish**.

Test the Zap. When the Zap is active, matching PostgreSQL rows trigger emails through Twilio SendGrid.

> \[!NOTE]
>
> If you ever want to change this PostgreSQL and SendGrid integration, just go to [your Zapier dashboard](https://zapier.com/app/dashboard) and tweak anything you'd like.

You can also check out all that's possible with [PostgreSQL on Zapier](https://zapier.com/zapbook/postgresql/), and other ways to connect [PostgreSQL and SendGrid](https://zapier.com/zapbook/postgresql/sendgrid).
