A simple email sending library with Jinja2 templates
Project description
Email Lib
Overview
Email Lib is a simple Python library for sending emails using SMTP and rendering email templates with Jinja2. It provides a clean and modular way to handle email functionality in your projects.
Features
- Dynamic email rendering using Jinja2 templates.
- Easy SMTP configuration for sending emails.
- Support for sending emails in plain text or HTML format.
- Optional file attachments.
- Lightweight and reusable library.
Installation
Install the package using pip:
pip install pyemaillib
Or install dependencies manually for local development:
pip install jinja2
Usage
Rendering an Email Template
from pyemaillib import render_template
from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader("templates"))
text = render_template(env, "otp_email.txt", otp="123456", expiry=10)
print(text)
Sending an Email
from pyemaillib import EmailSender
import asyncio
async def main():
email_sender = EmailSender(
smtp_host="smtp.example.com",
smtp_user="your_email@example.com",
smtp_pass="your_password",
from_email="your_email@example.com"
)
success = await email_sender.send_email(
text="Your OTP code is 123456.",
to_email="recipient@example.com",
subject="🔐 Your OTP Code",
text_type="plain",
attachments=[("filename.txt", "Sample content")] # Optional attachment
)
print("Email sent successfully!" if success else "Failed to send email.")
asyncio.run(main())
Configuration
Ensure you configure SMTP settings correctly before sending emails:
- smtp_host: Your SMTP server (e.g.,
smtp.gmail.comfor Gmail). - smtp_user: Your email address used for authentication.
- smtp_pass: Your email account password or app-specific password.
PyPI Link
https://pypi.org/project/pyemaillib/
Contributing
Feel free to submit pull requests or open issues for improvements.
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyemaillib-0.1.2.tar.gz.
File metadata
- Download URL: pyemaillib-0.1.2.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
93c605c4fe1de01a42415cb79dd015a2b9d7005a0cae2b574c165803242dde1d
|
|
| MD5 |
a58e397b8eaa1ec95212481786655384
|
|
| BLAKE2b-256 |
2fd325530c64740a0ac9b3dc120c45c9cfba7df92dca6402c0bed731c80943c0
|
File details
Details for the file pyemaillib-0.1.2-py3-none-any.whl.
File metadata
- Download URL: pyemaillib-0.1.2-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd70297fc066dc557c95797565fad50d6bf4e0951bda8910060a4fac8271f5ce
|
|
| MD5 |
ee34ddc34c1a0914b17731cf4660e87a
|
|
| BLAKE2b-256 |
7c24bff7365c13b82d39b342e1be283ebd5a884f4d08916bc8847de335e8f3d0
|