Skip to main content

Simple sending of smtp emails using env variables

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

envsmtp-0.4.0.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

envsmtp-0.4.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file envsmtp-0.4.0.tar.gz.

File metadata

  • Download URL: envsmtp-0.4.0.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.4

File hashes

Hashes for envsmtp-0.4.0.tar.gz
Algorithm Hash digest
SHA256 1f8892d48680a1824cdd6f87f8e0abfaa1c52f2425bbbcdb14deb1ed2b52f303
MD5 bdc3fcd64dbdaded3156e03b27558310
BLAKE2b-256 40451207e5040a84cc4749693b1ee71d91e43e4a391e591d23e21dc1967f3353

See more details on using hashes here.

File details

Details for the file envsmtp-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: envsmtp-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.4

File hashes

Hashes for envsmtp-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e10613ba572f3afb16707514ae1b8067e6a96b4600b5c76888b556161e290b16
MD5 f8b2785168b4ee46db9e7ac8dcdfdbf8
BLAKE2b-256 15f6f98915c7636206f0b8db4804ded35158dab45c64d12b1fedf845b2691087

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page