An email automation library using SendGrid API. Supports both single and batch email sending with Markdown formatting and template substitution.
- Single and batch email sending
- Markdown to HTML conversion with styling
- Template substitution support
- CSV and JSON data source support
- Preview and validation modes
pip install swecc-email-sender
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]"
)
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 = """
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"
}
)
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
to_email,name,order_id,address
[email protected],John Doe,12345,123 Main St
[email protected],Jane Smith,12346,456 Oak Ave
[
{
"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"
}
]
- Clone the repository:
git clone https://github.com/swecc/swecc-email-sender.git
cd swecc-email-sender
- Create a virtual environment and install dependencies:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -e ".[dev]"
pytest
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
This project is licensed under the MIT License - see the LICENSE file for details.