Send email messages and enforce encryption.
Project description
Bote
"Bote" is German for messenger or courier. The bote
library sends plain-text email from localhost or a remote SMTP server. The base functionality is in the standard library, but this package improves upon that in several ways:
- Enforce that any connection to a SMTP server - except
localhost
/127.0.0.1
/::1
- is encrypted. (Of course this does not influence how the SMTP server sends the message to the recipient.) - Good error messages
- Type-Hints in the code (PEP 484)
- Extensive testing
- Automatically wrap messages preserving intentional line-breaks.
How to use it
import os
import bote
mail_settings = {
'server': 'smtp.example.com',
'server_port': 587,
'encryption': 'starttls', # or 'ssl', or 'off'
# Best practice: get secrets from environment variables
# instead of hardcoded strings =>
'username': os.environ.get('MAIL_USER'),
'passphrase': os.environ.get('MAIL_PASSPHRASE'),
'recipient': 'foo@example.com',
'sender': 'bar@example.com',
'wrap_width': 80}
mailer = bote.Mailer(mail_settings)
mailer.send_mail('Test bote', # subject
'It worked!' # mail body
)
# If the setting recipient is a dictionary and contains
# an admin key:
mailer.send_mail_to_admin('Test', 'Message for the admin')
All parameters except recipient
and sender
are optional as bote
has defaults for all others:
Parameter | Default Value |
---|---|
server |
localhost |
server_port |
None |
encryption |
off |
username |
None |
passphrase |
None |
wrap_width |
80 |
The parameter recipient
can either be an email address as a string or a dictionary. In the later case, this should have a default
key with the standard recipient as value. Otherwise the recipient has to be set for every message. If it contains an admin
key, the shorthand command send_mail_to_admin
can be used.
Keeping Your Credentials Save
You should not store secrets in code that may be shared or saved to source control.
To avoid accidental exposure of secrets it is best practice to use environment variables that can be accessed with os.environ.get()
. The python-dotenv
could be useful for this too - do not forget to add .env
files to .gitignore
.
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
Built Distribution
File details
Details for the file bote-1.2.2.tar.gz
.
File metadata
- Download URL: bote-1.2.2.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.25.1 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 276c36b2c795d73c77cab0a5fcd1790929bfcfd8936f1d68f17ef0b4ab6b170e |
|
MD5 | aa1aa18fc9faf5d1e860dda5659f8cd4 |
|
BLAKE2b-256 | 7fb424296470d5a709b37a80aeda75fa196bf074134474be5c24ba691a98266a |
File details
Details for the file bote-1.2.2-py3-none-any.whl
.
File metadata
- Download URL: bote-1.2.2-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.25.1 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ce4daa554f27ae28fcdd4b7cb10c3c08778ded6cd5e971cc289c2a31ebed2b6 |
|
MD5 | 475d4d7df3d2db29977a1f14a533e2a0 |
|
BLAKE2b-256 | ad59824fd7cc755375c4db12a9f2d95d2c41b682f90335aac13f702980bb156d |