Skip to main content

Async bulk email sender with Jinja2 templates and CLI

Project description

mail-senderpy

Bulk email sender with Jinja2 templates and CLI.

Send personalized emails to a list of users using any SMTP provider (Gmail, Outlook, AWS SES, SendGrid, etc.).

Installation

pip install mail-senderpy

Quick Start

Python API

from mail_senderpy import send_message

result = send_message(
    env_path=".env",
    users_path="users.json",
    template_path="template.html",
)

print(result)
# {"success": 18, "failed": 2, "errors": [{"email": "...", "error": "..."}]}

Or use send_message_async in an async context:

from mail_senderpy import send_message_async

result = await send_message_async(
    env_path=".env",
    users_path="users.json",
    template_path="template.html",
)

CLI

mail-senderpy send --env .env --users users.json --template template.html

Options:

Flag Default Description
--env .env Path to .env file
--users users.json Path to users JSON file
--template template.html Path or built-in template name
--subject Hello, {{name}}! Email subject (Jinja2 supported)
--delay 10.0 Seconds between sends

Configuration

Create a .env file with your SMTP credentials:

SMTP_SERVER=smtp.gmail.com
SMTP_PORT=587
EMAIL_ADDRESS=your@email.com
EMAIL_PASSWORD=app_password
SMTP_TLS=true

All fields are required except SMTP_TLS (defaults to true).

Users JSON Format

[
  {"email": "user1@example.com", "name": "Rahul"},
  {"email": "user2@example.com", "name": "Priya"}
]

Each object's fields are available as Jinja2 template variables.

Templates

Custom Templates

Create an HTML file with Jinja2 placeholders:

<h1>Hello {{ name }}!</h1>
<p>We're reaching out to you at {{ email }}.</p>

Built-in Templates

Pass a built-in template name instead of a file path:

  • marketing_email.html — promotional layout with CTA button
  • feedback_request.html — feedback request with link
  • announcement.html — announcement layout
mail-senderpy send --template marketing_email.html

Return Value

{
  "success": 18,
  "failed": 2,
  "errors": [
    {"email": "user@test.com", "error": "SMTP authentication failed"}
  ]
}

Error Handling

The library validates all inputs before sending and raises descriptive errors:

  • ConfigError — missing or invalid .env file
  • UsersFileError — malformed JSON or invalid user entries
  • TemplateError — template file not found
from mail_senderpy import send_message, MailSenderError

try:
    result = send_message(env_path=".env", users_path="users.json", template_path="template.html")
except MailSenderError as e:
    print(f"Error: {e}")
    print(f"Details: {e.details}")

License

MIT

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

mail_senderpy-0.1.3.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

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

mail_senderpy-0.1.3-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file mail_senderpy-0.1.3.tar.gz.

File metadata

  • Download URL: mail_senderpy-0.1.3.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mail_senderpy-0.1.3.tar.gz
Algorithm Hash digest
SHA256 6de21b19363e05b39d61f1d9799767910f3f1502a75872eabb5c6b5cb15d03f4
MD5 d2016af1efafcd7b35faaa1e87af2159
BLAKE2b-256 b1979c0972a61cc9beaa35875c897c1903292b7ad821e5158a0a953a51eed8b9

See more details on using hashes here.

Provenance

The following attestation bundles were made for mail_senderpy-0.1.3.tar.gz:

Publisher: publish.yml on extinctsion/mail-sender

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mail_senderpy-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: mail_senderpy-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mail_senderpy-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5f9d2124518a8c81e74b651b6b82a985c18b053235f90d35e28ab49386cef12c
MD5 38db96064673810293daa7c5346d9749
BLAKE2b-256 91a3b69934e2bda03816533f095a519bb787efec5ecf6418988fd76b0c5d3cba

See more details on using hashes here.

Provenance

The following attestation bundles were made for mail_senderpy-0.1.3-py3-none-any.whl:

Publisher: publish.yml on extinctsion/mail-sender

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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