pg_smtp_client

使用SMTP从PostgreSQL内发送邮件的客户端扩展

扩展总览

PIGSTY 第三方扩展: pg_smtp_client : 使用SMTP从PostgreSQL内发送邮件的客户端扩展

基本信息

元数据

  • 默认版本: 0.2.0
  • PG大版本: 17,16,15,14
  • 动态加载: 无需动态加载
  • 需要DDL: 需要执行 CREATE EXTENSION DDL
  • 可重定位: 可以重定位安装至其他模式下
  • 信任程度: 受信任,无需超级用户,带 CREATE 权限的用户可以直接创建
  • 所需模式: smtp_client
  • 所需扩展: 无

软件包

  • RPM仓库:PIGSTY
  • RPM包名:pg_smtp_client_$v
  • RPM版本:0.2.0
  • RPM依赖:无
  • DEB仓库:PIGSTY
  • DEB包名:postgresql-$v-pg-smtp-client
  • DEB版本:0.2.0
  • DEB依赖:无

最新版本

系统 架构 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

扩展安装

使用 pig 命令行工具安装 pg_smtp_client 扩展:

pig ext install pg_smtp_client

使用 Pigsty剧本 安装 pg_smtp_client 扩展:

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

YUM仓库 手工安装 pg_smtp_client RPM 包:

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

APT仓库 手工安装 pg_smtp_client DEB 包:

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;

使用以下 SQL 命令在已经安装此扩展插件的 PG 集群上 启用 pg_smtp_client 扩展:

CREATE EXTENSION pg_smtp_client;

使用方法

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;

使用方法

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 'from@example.com';
SELECT pg_reload_conf();

示例

Send an email:

SELECT smtp_client.send_email('test subject', 'test body', false, 'from@example.com', array['to@example.com'], 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['to@example.com']);

Or, using named arguments:

SELECT smtp_client.send_email('test subject', 'test body', recipients => array['to@example.com']);




最后修改 2025-03-07: routine update (2106723)