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

pre-commit pre-commit.ci status CodeFactor Codeclimate CodeQl readthedocs Imports: isort 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 : sking.github@gmail.com

Distributed under the MIT license. See for more information.

Created with Cookiecutter template: pydough version 1.2.1

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

Uploaded Source

Built Distribution

pynnacle-1.1.2-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pynnacle-1.1.2.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/37.3 requests/2.28.2 requests-toolbelt/0.10.1 urllib3/1.26.14 tqdm/4.64.1 importlib-metadata/6.0.0 keyring/23.13.1 rfc3986/2.0.0 colorama/0.4.6 CPython/3.9.10

File hashes

Hashes for pynnacle-1.1.2.tar.gz
Algorithm Hash digest
SHA256 7c0ee089d5483bcaa72fcc2e7dbf6dfacda364aaaff4795488d03f8e392904fb
MD5 d029f31d041a3d21695e180f9b0739f3
BLAKE2b-256 4dedc4a89bb55998dc4fcbb4ff98bf1cb541a09733690b208aa4233f009ec159

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pynnacle-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/37.3 requests/2.28.2 requests-toolbelt/0.10.1 urllib3/1.26.14 tqdm/4.64.1 importlib-metadata/6.0.0 keyring/23.13.1 rfc3986/2.0.0 colorama/0.4.6 CPython/3.9.10

File hashes

Hashes for pynnacle-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 eb715acac6f7c8d994dd170ce9343709a07b46dbe228cb6db74090e298db026e
MD5 5ebb2adf9a6e299a9fc588f1ce179dcd
BLAKE2b-256 26fcdc350ac1898b48a505078216396a3638133b99499d2e1b1a603ef76c2c98

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