Skip to main content

boilerplate you need to create a Python package.

Project description

pynnacle

A utility class to simplify sending emails.

pre-commit Imports: isort Code style: black Checked with mypy security: bandit licence: mit

Installation

OS X & Linux:

pip3 install pynnacle

Windows:

pip install pynnacle

Usage example

Firstly import the module

import pynnacle

Then instantiate the class with the initialization arguments.

mailer = pynnacle.SendEmail(
    user_id=user_id,
    user_pass=user_pass,
    smtp_server=server,
    smtp_port=port,
    smtp_authentication=auth,
    smtp_encryption=encrypt,
)

Then simply send the email

mailer.message_send(
    subject="Hi There",
    sender="sender@abc.com",
    recipient="recipient@xyz.com",
    body="This is where the text of the email body goes",
)

cc, bcc and attachments arguments can also be used, supplied as lists

mailer.message_send(
    subject="Hi There",
    sender="sender@abc.com",
    recipient="recipient@xyz.com",
    body="This is where the text of the email body goes",
    cc=["person1@def.com", "person2@ghi.com"],
    bcc=["person3@jkl.com", "person4@mno.com"],
    attachments=["path_to_file1", "path_to_file2"]
)

Further simplifications

Storing and Reusing SMTP

Iy you have a requirement to use multiple SMTP servers then the settings can be stored in a config file:

e.g.config.ini

[gmail]
smtp_server = smtp.gmail.com
smtp_port = 587
smtp_authentication = yes
smtp_encryption = yes
pop3_server = pop.gmail.com
pop3_port = 995
pop3_authentication = yes
pop3_encryption = yes

Then in your application simply specify the "service" and extract the required elements with the Python configparser library.

import configparser

service = "gmail"

ini = configparser.ConfigParser()
ini.read("config.ini")
server = ini.get(service, "smtp_server")
port = int(ini.get(service, "smtp_port"))
auth = ini.get(service, "smtp_authentication")
encrypt = ini.get(service, "smtp_encryption")

Storing credentials

To avoid hard-coding any credentials I use the Python keyring library

service = "gmail"

user_id = keyring.get_password(service, "service_id")
user_pass = keyring.get_password(service, "service_password")

For more examples and usage, please refer to the Wiki.

Development setup

Describe how to install all development dependencies and how to run an automated test-suite of some kind. Potentially do this for multiple platforms.

pip install --editable pynnacle

Release History

  • v 1.0.0
    • Released and stable

Meta

Stephen R A King : name@isp.com

Distributed under the MIT License. See LICENSE for more information.

https://github.com/Stephen-RA-King/pynnacle

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

pynnacle-1.0.0.tar.gz (12.0 kB view hashes)

Uploaded Source

Built Distribution

pynnacle-1.0.0-py3-none-any.whl (6.5 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