Skip to content

swecc-uw/swecc-email-sender

Repository files navigation

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="[email protected]",
    subject="Hello!",
    content="This is a test email",
    from_email="[email protected]"
)

Markdown Email

success = sender.send_email(
    to_email="[email protected]",
    subject="Hello!",
    content="# Hello World\n\nThis is a **markdown** email",
    from_email="[email protected]",
    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="[email protected]",
    subject="Order #{order_id} Shipped",
    content=template,
    from_email="[email protected]",
    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 [email protected] --to [email protected] --subject "Hello" --content "Test email"

# Markdown email
swecc-email-sender --from [email protected] --to [email protected] --subject "Hello" --content "# Hello" --markdown

# Template with CSV data
swecc-email-sender --from [email protected] --src recipients.csv --subject "Hello {name}" --template email.md

# Preview first email
swecc-email-sender --from [email protected] --src data.json --subject "Hello" --template email.md --preview

# Validate templates
swecc-email-sender --from [email protected] --src data.json --subject "Hello {name}" --template email.md --validate

Data File Formats

CSV Example (recipients.csv)

to_email,name,order_id,address
[email protected],John Doe,12345,123 Main St
[email protected],Jane Smith,12346,456 Oak Ave

JSON Example (data.json)

[
  {
    "to_email": "[email protected]",
    "name": "John Doe",
    "order_id": "12345",
    "address": "123 Main St"
  },
  {
    "to_email": "[email protected]",
    "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.

About

No description or website provided.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages