Skip to main content

envsmtp

Latest Release envsmtp on pypi MIT License Python package tests

Simple sending of smtp emails using environment variables

Install

envsmtp on pypi envsmtp

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=false
  • SMTP_USE_SSL=false
  • SMTP_NO_AUTH=true
  • SMTP_FROM=sender@example.com (required whenever SMTP_USER is 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=Tests
  • SMTP_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

envsmtp

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

Open Issues Closed Issues

If you would like to contribute to this project, you are welcome to submit a pull request

Open Pull Requests Closed Pull Requests

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

Code Size Pypi downloads per month Pypi downloads per week Pypi downloads per day

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)

Source distribution for envsmtp 0.4.0
File Size Uploaded
envsmtp-0.4.0.tar.gz 6.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for envsmtp 0.4.0
File Interpreter ABI Platform
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

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.0

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page