Skip to main content

A production-ready email automation library using SendGrid

Project description

SWECC Email Sender

An email automation library using SendGrid API. Supports both single and batch email sending with Markdown formatting and template substitution.

Features

  • Single and batch email sending
  • Markdown to HTML conversion with styling
  • Template substitution support
  • CSV and JSON data source support
  • Preview and validation modes

Installation

pip install swecc-email-sender

Quick Start

Single Email

from swecc_email_sender import EmailSender

sender = EmailSender()  # uses SENDGRID_API_KEY environment variable
success = sender.send_email(
    to_email="recipient@example.com",
    subject="Hello!",
    content="This is a test email",
    from_email="sender@example.com"
)

Markdown Email

success = sender.send_email(
    to_email="recipient@example.com",
    subject="Hello!",
    content="# Hello World\n\nThis is a **markdown** email",
    from_email="sender@example.com",
    is_markdown=True
)

Template Email

template = """
Hello {name}!

Your order #{order_id} has been shipped to:
{address}

Thank you for your business!
"""

success = sender.send_email(
    to_email="customer@example.com",
    subject="Order #{order_id} Shipped",
    content=template,
    from_email="shop@example.com",
    template_data={
        "name": "John Doe",
        "order_id": "12345",
        "address": "123 Main St, City, Country"
    }
)

Command Line Interface

The package includes a command-line interface for easy use:

# Single email
swecc-email-sender --from sender@example.com --to recipient@example.com --subject "Hello" --content "Test email"

# Markdown email
swecc-email-sender --from sender@example.com --to recipient@example.com --subject "Hello" --content "# Hello" --markdown

# Template with CSV data
swecc-email-sender --from sender@example.com --src recipients.csv --subject "Hello {name}" --template email.md

# Preview first email
swecc-email-sender --from sender@example.com --src data.json --subject "Hello" --template email.md --preview

# Validate templates
swecc-email-sender --from sender@example.com --src data.json --subject "Hello {name}" --template email.md --validate

Data File Formats

CSV Example (recipients.csv)

to_email,name,order_id,address
customer1@example.com,John Doe,12345,123 Main St
customer2@example.com,Jane Smith,12346,456 Oak Ave

JSON Example (data.json)

[
  {
    "to_email": "customer1@example.com",
    "name": "John Doe",
    "order_id": "12345",
    "address": "123 Main St"
  },
  {
    "to_email": "customer2@example.com",
    "name": "Jane Smith",
    "order_id": "12346",
    "address": "456 Oak Ave"
  }
]

Development

Setup

  1. Clone the repository:
git clone https://github.com/swecc/swecc-email-sender.git
cd swecc-email-sender
  1. Create a virtual environment and install dependencies:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -e ".[dev]"

Running Tests

pytest

Code Style

The project uses:

  • Black for code formatting
  • isort for import sorting
  • mypy for type checking
  • flake8 for linting

To run all checks:

ruff --fix
isort .
mypy swecc_email_sender
flake8 swecc_email_sender

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

swecc_email_sender-1.0.2.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

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

swecc_email_sender-1.0.2-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file swecc_email_sender-1.0.2.tar.gz.

File metadata

  • Download URL: swecc_email_sender-1.0.2.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for swecc_email_sender-1.0.2.tar.gz
Algorithm Hash digest
SHA256 c44afc2c1f4dddba1d46900473bd8636996e6f9a5f6aaa24c4eac4431f6d0617
MD5 c8eb153eefdc2a524e2a8fa837e93b0c
BLAKE2b-256 8d1566c40b941baeae3264c67da6d21e3863a3fd38dc3d54884f9fb306aa2072

See more details on using hashes here.

File details

Details for the file swecc_email_sender-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for swecc_email_sender-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 aba1e2d5fce21768fc92fa6b8fffbd24b5df9c03275b977bef010e25616ccc9c
MD5 090cb732743aa952a0004fb1f4dfb67f
BLAKE2b-256 1251a59620fd2777e5fdbd3701a8bcd4b2e8afcdeaf422a5e770f46584956f99

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