Lightweight Gmail notification wrapper
Project description
sygmail
Lightweight wrapper for sending Gmail notifications with simple defaults and a .env config.
Features
- Load settings from
.envand environment variables - Save settings from code (
persist=True) - Defaults for subject/contents with
{script_name}placeholder - Optional auto-attachments from a path
Install
pip install sygmail
Requirements
- Python 3.9+
- Dependency:
yagmail
Quick start
from sygmail import Sygmail
syg = Sygmail()
syg.configure(
from_addr="you@gmail.com",
app_password="app-password",
persist=True,
)
syg.send()
.env keys
SYGMAIL_FROM=you@gmail.com
SYGMAIL_APP_PASSWORD=app-password
SYGMAIL_TO=to@example.com
SYGMAIL_SUBJECT=Process Completed
SYGMAIL_CONTENTS={script_name} has finished running.
SYGMAIL_ATTACHMENTS_PATH=./a/
Defaults
- Subject:
Process Completed - Contents:
{script_name} has finished running.
Reset back to defaults:
syg.reset_subject_contents(persist=True)
Attachments behavior
- If
attachmentsis provided insend(), it is used as-is. - If
attachmentsis not provided, andSYGMAIL_ATTACHMENTS_PATHis set, files under that path are attached (files only, no folders).
Examples:
syg.send(attachments=["./a/file.txt"]) # use only this
syg.send(attachments=[]) # explicitly no attachments
syg.send() # auto-attach from SYGMAIL_ATTACHMENTS_PATH if set
CLI
Use python -m sygmail for now:
python -m sygmail send
Options:
python -m sygmail send \
--env .env \
--from you@gmail.com \
--to to@example.com \
--subject "Process Completed" \
--contents "[sygmail notification]" \
--attachments ./path/to/file \
--attachments-path ./path/to/folder/
- If
--contentsis omitted, CLI uses[sygmail notification]without editing.env.
Common examples:
python -m sygmail send
python -m sygmail send --subject "Job Done" --contents "[sygmail notification]"
python -m sygmail send --attachments ./a/a.txt ./a/b.txt
python -m sygmail config set --from you@gmail.com --app-password "app-password"
python -m sygmail config show
Config commands:
python -m sygmail config set \
--env .env \
--from you@gmail.com \
--app-password "app-password" \
--to to@example.com \
--subject "Process Completed" \
--contents "{script_name} has finished running." \
--attachments-path ./a/
python -m sygmail config reset --env .env
python -m sygmail config show --env .env
python -m sygmail config show --env .env --raw
API
Sygmail(env_path=".env")
Sygmail.configure(
from_addr=None,
from_=None,
app_password=None,
to=None,
subject=None,
contents=None,
attachments_path=None,
persist=True,
)
Sygmail.reset_subject_contents(persist=True)
Sygmail.send(
from_addr=None,
from_=None,
to=None,
subject=None,
contents=None,
attachments=None,
attachments_path=None,
**kwargs,
)
Notes
- Use a Gmail app password (not your normal password).
- Settings are stored in
.envin the current working directory by default. - If
tois omitted, the message is sent to the same address asfrom_addr.
Security
- Do not commit
.envto public repos. - Treat app passwords like secrets.
Operations
- Prefer
chmod 600 .envon shared machines. - Use
--envto separate configs per project.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sygmail-0.1.0.tar.gz
(7.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sygmail-0.1.0.tar.gz.
File metadata
- Download URL: sygmail-0.1.0.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a3a083ad39ee8182a88dda25bf33462733217c52f2bb5f23caec6deb220106c
|
|
| MD5 |
f293cfcd24bca426c8eb230f4256ca3b
|
|
| BLAKE2b-256 |
97d1afecd11def9290e4f2813d21cb331aa8a7efb580e9a676890b95950e9fe3
|
File details
Details for the file sygmail-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sygmail-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a727e4d5b4a8f9c0287a94f6295b032ea92d347190e6b385a2b8b4d858049240
|
|
| MD5 |
8d6e135a7e8f7e2f5b5f47008fe3158d
|
|
| BLAKE2b-256 |
701fd215dd86aa0e828c1175f8275bd0691b853ff9430ba1f6c40c5e4cf7923a
|