envsmtp
Simple sending of smtp emails using environment variables
Install
pip install --upgrade envsmtp
Environment Variables
By default (STARTTLS + auth mode), you must set SMTP_USER and SMTP_PASS in your environment.
To send without TLS/SSL/auth, set:
SMTP_USE_TLS=falseSMTP_USE_SSL=falseSMTP_NO_AUTH=trueSMTP_FROM=sender@example.com(required wheneverSMTP_USERis not set, regardless of auth mode, or if you want to use a different sender than the SMTP_USER email)
Alternatively, you may set both SMTP_FROM_NAME and SMTP_FROM_EMAIL instead of SMTP_FROM:
SMTP_FROM_NAME=TestsSMTP_FROM_EMAIL=tests@example.com
See additional optional settings in example.env
Usage
This package defaults to STARTTLS on smtp.gmail.com:587 with SMTP auth enabled.
You can change host/port with SMTP_HOST and SMTP_PORT, and transport/auth behavior with:
SMTP_USE_TLS(default:true)SMTP_USE_SSL(default:false)SMTP_NO_AUTH(default:false)
Once installed, here's a simple example of how to use this package:
from envsmtp import EmailMessage
msg = EmailMessage(
sender="sender@example.com",
recipients="recipient@example.com",
subject="envsmtp test",
body="This is just a test message",
)
msg.smtp_send()
To send with attachments:
from envsmtp import EmailMessage, EmailAttachment
attachments = [
EmailAttachment(content='/path/to/file.txt'),
EmailAttachment(content=b'randombytes', filename='bytes_test.txt'),
EmailAttachment(content='/path/to/another.txt', filename='this_name_is_different_.txt')
]
msg = EmailMessage(
sender="sender@example.com",
recipients="recipient@example.com",
subject="envsmtp test",
body="This is just a test message",
attachments=attachments,
)
msg.smtp_send()
Requirements
Supports Python 3.10 and above (currently tested in CI on 3.10-3.13). Project dependencies are defined in pyproject.toml.
Testing
Install project + dev dependencies:
uv sync --locked --group dev
Run all tests (default + integration) with coverage using a single command:
just test
Integration tests require SMTP_USER, SMTP_PASS, and SMTP_TEST. If missing, integration tests are skipped.
Contributing
For bugs / feature requests please submit issues
If you would like to contribute to this project, you are welcome to submit a pull request
Warranty / Liability / Official support
This project is being developed independently, we provide the package "as-is" without any implied warranty or liability, usage is your own responsibility
Additional info
Just because I like badges
Release files for envsmtp 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| envsmtp-0.4.0.tar.gz | 6.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| envsmtp-0.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.6 kB
Release files / envsmtp-0.4.0.tar.gz
| Download URL | envsmtp-0.4.0.tar.gz |
|---|---|
| Size | 6.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1f8892d48680a1824cdd6f87f8e0abfaa1c52f2425bbbcdb14deb1ed2b52f303
|
|
BLAKE2b-256 checksum How to use checksums |
40451207e5040a84cc4749693b1ee71d91e43e4a391e591d23e21dc1967f3353
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.4
|
Release files / envsmtp-0.4.0-py3-none-any.whl
| Download URL | envsmtp-0.4.0-py3-none-any.whl |
|---|---|
| Size | 5.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e10613ba572f3afb16707514ae1b8067e6a96b4600b5c76888b556161e290b16
|
|
BLAKE2b-256 checksum How to use checksums |
15f6f98915c7636206f0b8db4804ded35158dab45c64d12b1fedf845b2691087
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.4
|