pg_smtp_client

PostgreSQL extension to send email using SMTP

Overview

PIGSTY 3rd Party Extension: pg_smtp_client : PostgreSQL extension to send email using SMTP

Information

Metadata

  • Latest Version: 0.2.0
  • Postgres Support: 17,16,15,14
  • Need Load: Shared library do not need explicit loading
  • Need DDL: Need CREATE EXTENSION DDL
  • Relocatable: Can be installed into other schemas
  • Trusted: Trusted, Can be created by user with CREATE Privilege
  • Schemas: smtp_client
  • Requires: N/A

RPM / DEB

  • RPM Repo: PIGSTY
  • RPM Name: pg_smtp_client_$v
  • RPM Ver : 0.2.0
  • RPM Deps: N/A
  • DEB Repo: PIGSTY
  • DEB Name: postgresql-$v-pg-smtp-client
  • DEB Ver : 0.2.0
  • DEB Deps: N/A

Packages

OS Arch PG17 PG16 PG15 PG14 PG13
el8 x86_64 pg_smtp_client_17
PIGSTY 0.2.0
pg_smtp_client_16
PIGSTY 0.2.0
pg_smtp_client_15
PIGSTY 0.2.0
pg_smtp_client_14
PIGSTY 0.2.0
el8 aarch64 pg_smtp_client_17
PIGSTY 0.2.0
pg_smtp_client_16
PIGSTY 0.2.0
pg_smtp_client_15
PIGSTY 0.2.0
pg_smtp_client_14
PIGSTY 0.2.0
el9 x86_64 pg_smtp_client_17
PIGSTY 0.2.0
pg_smtp_client_16
PIGSTY 0.2.0
pg_smtp_client_15
PIGSTY 0.2.0
pg_smtp_client_14
PIGSTY 0.2.0
el9 aarch64 pg_smtp_client_17
PIGSTY 0.2.0
pg_smtp_client_16
PIGSTY 0.2.0
pg_smtp_client_15
PIGSTY 0.2.0
pg_smtp_client_14
PIGSTY 0.2.0
d12 x86_64 postgresql-17-pg-smtp-client
PIGSTY 0.2.0
postgresql-16-pg-smtp-client
PIGSTY 0.2.0
postgresql-15-pg-smtp-client
PIGSTY 0.2.0
postgresql-14-pg-smtp-client
PIGSTY 0.2.0
d12 aarch64 postgresql-17-pg-smtp-client
PIGSTY 0.2.0
postgresql-16-pg-smtp-client
PIGSTY 0.2.0
postgresql-15-pg-smtp-client
PIGSTY 0.2.0
postgresql-14-pg-smtp-client
PIGSTY 0.2.0
u22 x86_64 postgresql-17-pg-smtp-client
PIGSTY 0.2.0
postgresql-16-pg-smtp-client
PIGSTY 0.2.0
postgresql-15-pg-smtp-client
PIGSTY 0.2.0
postgresql-14-pg-smtp-client
PIGSTY 0.2.0
u22 aarch64 postgresql-17-pg-smtp-client
PIGSTY 0.2.0
postgresql-16-pg-smtp-client
PIGSTY 0.2.0
postgresql-15-pg-smtp-client
PIGSTY 0.2.0
postgresql-14-pg-smtp-client
PIGSTY 0.2.0
u24 x86_64 postgresql-17-pg-smtp-client
PIGSTY 0.2.0
postgresql-16-pg-smtp-client
PIGSTY 0.2.0
postgresql-15-pg-smtp-client
PIGSTY 0.2.0
postgresql-14-pg-smtp-client
PIGSTY 0.2.0
u24 aarch64 postgresql-17-pg-smtp-client
PIGSTY 0.2.0
postgresql-16-pg-smtp-client
PIGSTY 0.2.0
postgresql-15-pg-smtp-client
PIGSTY 0.2.0
postgresql-14-pg-smtp-client
PIGSTY 0.2.0

Installation

Install pg_smtp_client via the pig CLI tool:

pig ext install pg_smtp_client

Install pg_smtp_client via Pigsty playbook:

./pgsql.yml -t pg_extension -e '{"pg_extensions": ["pg_smtp_client"]}' # -l <cls>

Install pg_smtp_client RPM from YUM repo directly:

dnf install pg_smtp_client_17;
dnf install pg_smtp_client_16;
dnf install pg_smtp_client_15;
dnf install pg_smtp_client_14;

Install pg_smtp_client DEB from APT repo directly:

apt install postgresql-17-pg-smtp-client;
apt install postgresql-16-pg-smtp-client;
apt install postgresql-15-pg-smtp-client;
apt install postgresql-14-pg-smtp-client;

Enable pg_smtp_client extension on PostgreSQL cluster:

CREATE EXTENSION pg_smtp_client;

Usage

https://github.com/frectonz/pglite-fusion/blob/main/README.md

Enabling the extension

Connect to postgres and run the following command.

CREATE EXTENSION IF NOT EXISTS pg_smtp_client CASCADE;

Usage

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

Function Parameters

Parameter Type Description System Configuration (Optional)
subject text The subject of the email
body text The body of the email
html boolean Whether the body is HTML (true) or plain text (false)
from_address text The from email address smtp_client.from_address
recipients text[] The email addresses of the recipients
ccs text[] The email addresses to CCs
bccs text[] The email addresses to BCCs
smtp_server text The SMTP server to use smtp_client.server
smtp_port integer The port of the SMTP server smtp_client.port
smtp_tls boolean Whether to use TLS smtp_client.tls
smtp_username text The username for the SMTP server smtp_client.username
smtp_password text The password for the SMTP server smtp_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 2025-02-17: add extension part (cfa504b)