Skip to content

ofersadan85/envsmtp

Repository files navigation

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

About

Simple sending of smtp emails using env variables

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

 
 
 

Contributors