Skip to main content

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

Metadata

Release files for pynnacle 1.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pynnacle 1.1.2
File Size Uploaded
pynnacle-1.1.2.tar.gz 13.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pynnacle 1.1.2
File Interpreter ABI Platform
pynnacle-1.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 22.6 kB

Release files / pynnacle-1.1.2.tar.gz

Download URL pynnacle-1.1.2.tar.gz
Size 13.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7c0ee089d5483bcaa72fcc2e7dbf6dfacda364aaaff4795488d03f8e392904fb
BLAKE2b-256 checksum
How to use checksums
4dedc4a89bb55998dc4fcbb4ff98bf1cb541a09733690b208aa4233f009ec159
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / pynnacle-1.1.2-py3-none-any.whl

Download URL pynnacle-1.1.2-py3-none-any.whl
Size 9.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eb715acac6f7c8d994dd170ce9343709a07b46dbe228cb6db74090e298db026e
BLAKE2b-256 checksum
How to use checksums
26fcdc350ac1898b48a505078216396a3638133b99499d2e1b1a603ef76c2c98
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

1.1.2 This release

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page