Skip to main content

Utility wrapper class to leverage email transmission

Project description

pynnacle

A utility class to simplify sending emails.

PyPI Downloads Status Python Version Format Requirements tests Codecov CodeFactor Codeclimate Lgtm alerts Lgtm quality CodeQl readthedocs pre-commit pre-commit.ci status Code style: black Checked with mypy security: bandit Commitizen friendly Conventional Commits DeepSource license

Pynnacle provides a wrapper to mimetypes, smtplib and email.message libraries to provide a simplified facade interface to make sending emails as simple as possible. It abstracts away all the low level details and when imported into other modules provides a clean, clutter-free interface.

Installation

OS X & Linux:

pip3 install pynnacle

Windows:

pip install pynnacle

Usage example

Firstly import the module

from pynnacle.pynnacle import SendEmail

Pynnacle stores the configuration of email servers in an 'ini' configuration file. If a service is already configured then the main class can be instantiated with only 3 arguments e.g.:

mailer = SendEmail(
    service="gmail"
    user_id="jsmith",
    user_pass="P@zzw0rd1",
)

If the service has not been configured, simply pass "custom" as the service and pass the other smtp arguments to the initializer e.g.:

mailer = SendEmail(
    service="custom"
    user_id="jsmith",
    user_pass="P@zzw0rd1",
    smtp_server="smtp.abc.com",
    smtp_port=25,
    smtp_authentication="yes",
    smtp_encryption="yes",
)

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

Additional setting can be saved in the "ini" file as and when you like.

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

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.

A Note on gmail authentication

As of 30/05/2022 Google will no longer support the use of third-party apps or devices that only ask for your username and password. The "Less secure app access" setting has now been turned off. The application now has to be assigned a 16 byte code which can be configured from your account as follows:

  • 1 Log onto your account: https://myaccount.google.com
  • 2 Goto security
  • 3 Enable 2-step verification
  • 4 click "App password" to generate the key

Then simply use this along with the account email address to authenticate

Documentation

- Read the Docs

- Wiki

Meta

Stephen R A King : stephen.ra.king@gmail.com

Distributed under the MIT license. See license for more information.

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

Created with Cookiecutter template: cc_template version 1.2.0

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.1.0.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

pynnacle-1.1.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file pynnacle-1.1.0.tar.gz.

File metadata

  • Download URL: pynnacle-1.1.0.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/35.0 requests/2.28.1 requests-toolbelt/0.9.1 urllib3/1.26.11 tqdm/4.64.0 importlib-metadata/4.12.0 keyring/23.7.0 rfc3986/2.0.0 colorama/0.4.5 CPython/3.9.10

File hashes

Hashes for pynnacle-1.1.0.tar.gz
Algorithm Hash digest
SHA256 b50f9d96d8e84a60ad40a71c35e3917502ac27788f0c4160b1c5b3664ec60c6e
MD5 e1c64053db620f6774375db54abfcf52
BLAKE2b-256 5afee40f2c36bfa86b59f0ebed31b3b315b49db344f97435072a5923c58e68eb

See more details on using hashes here.

File details

Details for the file pynnacle-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: pynnacle-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/35.0 requests/2.28.1 requests-toolbelt/0.9.1 urllib3/1.26.11 tqdm/4.64.0 importlib-metadata/4.12.0 keyring/23.7.0 rfc3986/2.0.0 colorama/0.4.5 CPython/3.9.10

File hashes

Hashes for pynnacle-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9479d6b03c219771f5258d0ee1c5f697989ad11b616b3141d1a4f7d34cb9d467
MD5 58c58fcefe536fc6fb19f4d3e74fc27c
BLAKE2b-256 17c34558d5175174c28fc91a041e471ae5b0e00ae80832a18997c611a38fc435

See more details on using hashes here.

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