pg_smtp_client

PostgreSQL extension to send email using SMTP

Overview

PackageVersionCategoryLicenseLanguage
pg_smtp_client0.2.1UTILMITRust
IDExtensionBinLibLoadCreateTrustRelocSchema
4170pg_smtp_clientNoYesNoYesYesNosmtp_client
Relatedhttp pg_net pg_html5_email_address gzip bzip zstd pg_curl pgjq

manual updated pgrx by Vonng

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY0.2.11817161514pg_smtp_client-
RPMPIGSTY0.2.11817161514pg_smtp_client_$v-
DEBPIGSTY0.2.11817161514postgresql-$v-pg-smtp-client-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
PIGSTY 0.2.1
PIGSTY 0.2.1
PIGSTY 0.2.1
PIGSTY 0.2.1
PIGSTY 0.2.1
d13.x86_64
PIGSTY 0.2.1
PIGSTY 0.2.1
PIGSTY 0.2.1
PIGSTY 0.2.1
PIGSTY 0.2.1
d13.aarch64
PIGSTY 0.2.1
PIGSTY 0.2.1
PIGSTY 0.2.1
PIGSTY 0.2.1
PIGSTY 0.2.1
u22.x86_64
PIGSTY 0.2.1
PIGSTY 0.2.1
PIGSTY 0.2.1
PIGSTY 0.2.1
PIGSTY 0.2.1
u22.aarch64
PIGSTY 0.2.1
PIGSTY 0.2.1
PIGSTY 0.2.1
PIGSTY 0.2.1
PIGSTY 0.2.1
u24.x86_64
PIGSTY 0.2.1
PIGSTY 0.2.1
PIGSTY 0.2.1
PIGSTY 0.2.1
PIGSTY 0.2.1
u24.aarch64
PIGSTY 0.2.1
PIGSTY 0.2.1
PIGSTY 0.2.1
PIGSTY 0.2.1
PIGSTY 0.2.1

Build

You can build the RPM / DEB packages for pg_smtp_client using pig build:

pig build pkg pg_smtp_client         # build RPM / DEB packages

Install

You can install pg_smtp_client directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

pig repo add pgsql -u          # Add repo and update cache

Install the extension using pig or apt/yum/dnf:

pig install pg_smtp_client;          # Install for current active PG version
pig ext install -y pg_smtp_client -v 18  # PG 18
pig ext install -y pg_smtp_client -v 17  # PG 17
pig ext install -y pg_smtp_client -v 16  # PG 16
pig ext install -y pg_smtp_client -v 15  # PG 15
pig ext install -y pg_smtp_client -v 14  # PG 14
dnf install -y pg_smtp_client_18       # PG 18
dnf install -y pg_smtp_client_17       # PG 17
dnf install -y pg_smtp_client_16       # PG 16
dnf install -y pg_smtp_client_15       # PG 15
dnf install -y pg_smtp_client_14       # PG 14
apt install -y postgresql-18-pg-smtp-client   # PG 18
apt install -y postgresql-17-pg-smtp-client   # PG 17
apt install -y postgresql-16-pg-smtp-client   # PG 16
apt install -y postgresql-15-pg-smtp-client   # PG 15
apt install -y postgresql-14-pg-smtp-client   # PG 14

Create Extension:

CREATE EXTENSION pg_smtp_client;

Usage

Enabling the extension

Connect to postgres and run the following command.

CREATE EXTENSION IF NOT EXISTS pg_smtp_client CASCADE;

Use the smtp_client.send_email() function to send an email.

Function Parameters

ParameterTypeDescriptionSystem Configuration (Optional)
subjecttextThe subject of the email
bodytextThe body of the email
htmlbooleanWhether the body is HTML (true) or plain text (false)
from_addresstextThe from email addresssmtp_client.from_address
recipientstext[]The email addresses of the recipients
ccstext[]The email addresses to CCs
bccstext[]The email addresses to BCCs
smtp_servertextThe SMTP server to usesmtp_client.server
smtp_portintegerThe port of the SMTP serversmtp_client.port
smtp_tlsbooleanWhether to use TLSsmtp_client.tls
smtp_usernametextThe username for the SMTP serversmtp_client.username
smtp_passwordtextThe password for the SMTP serversmtp_client.password

Default Configuration

You can configure the following system-wide default values for some of the parameters (as indiciated in the table above) like this:

ALTER SYSTEM SET smtp_client.server TO 'smtp.example.com';
ALTER SYSTEM SET smtp_client.port TO 587;
ALTER SYSTEM SET smtp_client.tls TO true;
ALTER SYSTEM SET smtp_client.username TO 'MySmtpUsername';
ALTER SYSTEM SET smtp_client.password TO 'MySmtpPassword';
ALTER SYSTEM SET smtp_client.from_address TO '[email protected]';
SELECT pg_reload_conf();

Usage Examples

Send an email:

SELECT smtp_client.send_email('test subject', 'test body', false, '[email protected]', array['[email protected]'], null, null, 'smtp.example.com', 587, true, 'username', 'password');

Send an email using configured default values:

SELECT smtp_client.send_email('test subject', 'test body', false, null, array['[email protected]']);

Or, using named arguments:

SELECT smtp_client.send_email('test subject', 'test body', recipients => array['[email protected]']);

Last Modified 2026-03-12: add pg extension catalog (95749bf)