Skip to main content

The classic email sending library for Python was expanded to include more useful features

Project description

PyMailers

The classic email sending library for Python, now with enhanced features like HTML templates and attachment support.

Installation

To install PyMailers, run the following command:

pip install pymailers

Features

Send emails with HTML content. Support for secure SMTP connections using starttls. Ability to send emails with attachments. Templating support using Jinja2 for dynamic email bodies. Optional logging for successful and failed email deliveries. Requirements Ensure you have the following Python modules installed: smtplib email os sys jinja2 (for templating) logging (for logging support)

You can install the required modules using pip:

pip install -r requirements.txt

Usage

PyMailers is simple to use yet powerful. Here's a quick example of sending an email with a plain text body. You can set display to False to suppress logs, or True to print logs after sending the email.

from pymailers.PyMailer import PyMailer

pymailer = PyMailer({
    'smtp_host': 'smtp.gmail.com',
    'smtp_port': 587,
    'email': 'your-email@gmail.com',
    'password': 'your-password',
    'to': 'recipient-email@gmail.com',
    'subject': 'Hello World',
    'body': '<p>Hi, I'm Rio</p>',
    'display': True
})

pymailer.send()

To send an email with attachments and using an HTML template:

pymailer = PyMailer({
    'smtp_host': 'smtp.gmail.com',
    'smtp_port': 587,
    'email': 'your-email@gmail.com',
    'password': 'your-password',
    'to': 'recipient-email@gmail.com',
    'subject': 'Greetings',
    'body': '', # Body will be generated by the template
    'display': True,
    'attachments': ['path/to/attachment1.pdf', 'path/to/image.jpg'],
    'template_path': 'path/to/template.html',
    'template_context': {'name': 'Rio'}
})

pymailer.send()

Make sure to replace the placeholders with your actual SMTP settings, email credentials, and file paths.

Logging All operations are logged into pymailer.log. This is helpful for auditing and debugging purposes.

Donate

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

pymailers-2.0.2.tar.gz (3.1 kB view hashes)

Uploaded Source

Built Distribution

pymailers-2.0.2-py3-none-any.whl (3.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page