pgsmtp
pgsmtp · Send SMTP email and file attachments from PostgreSQL using untrusted PL/Python functions.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100354 | pgsmtp | pgsmtp | 0.1.1 | UTIL | PostgreSQL | Python |
PostgreSQL · 10, 11, 12, 13, 14, 15, 16, 17, 18
| Relationships | |
|---|---|
| Requires | plpython3u |
Usage
Sources:
pgsmtp sends email from PostgreSQL through Python’s SMTP client. Version 0.1.1 creates a pgsmtp.user_smtp_data table for sender/server/password records and provides pgsmtp.pg_smtp_mail() plus the attachment-capable pgsmtp.pg_smtp_mail_attach(). It requires the untrusted plpython3u language and superuser installation.
Configure a sender and send mail
The implementation uses SMTP_SSL, stores passwords as plaintext, and performs network I/O inside the database backend. More seriously, it concatenates the caller-supplied sender into a PL/Python SQL query, creating SQL-injection risk. pgsmtp.pg_smtp_mail_attach() also reads arbitrary server-side paths as the PostgreSQL operating-system account.
Upstream warns that bugs remain and describes the extension as administrator-only. Do not grant its schema, credential table, or function execution to application roles. Prefer an external mail queue; if legacy use is unavoidable, parameterize the lookup, encrypt or externalize credentials, restrict egress and file access, add timeouts/auditing, and test SMTP failure behavior before deployment.