Skip to main content

Lightweight Gmail notification wrapper

Project description

sygmail

Lightweight wrapper for sending Gmail notifications with simple defaults and a .env config.

Features

  • Load settings from .env and 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
  • Optional: keyring (for OS credential store support)

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=/path/to/folder

If you use keyring, you can leave SYGMAIL_APP_PASSWORD empty.

Install keyring support:

pip install "sygmail[keyring]"

Keyring usage:

python -m sygmail config set --from you@gmail.com --app-password "app-password" --use-keyring
python -m sygmail send

Notes:

  • Passwords are stored under the service name sygmail with the from address as the username.
  • If SYGMAIL_APP_PASSWORD is set, it is used first; otherwise keyring is used.
  • Storage uses your OS credential manager (macOS Keychain, Windows Credential Manager, or a Linux keyring).
  • To remove a stored password, delete it from your OS credential manager.

Defaults

  • Subject: Process Completed
  • Contents: {script_name} has finished running.

Reset back to defaults:

syg.reset_subject_contents(persist=True)

Attachments behavior

  • If attachments is provided in send(), it is used as-is.
  • If attachments is not provided, and SYGMAIL_ATTACHMENTS_PATH is 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 --contents is 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 /path/to/file-a.txt /path/to/file-b.txt

python -m sygmail send --attachments-path /path/to/folder/

python -m sygmail config set --from you@gmail.com --app-password "app-password"

python -m sygmail config set --from you@gmail.com --app-password "app-password" --use-keyring

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 /path/to/folder/

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 .env in the current working directory by default.
  • If to is omitted, the message is sent to the same address as from_addr.

Security

  • Do not commit .env to public repos.
  • Treat app passwords like secrets.

Operations

  • Prefer chmod 600 .env on shared machines.
  • Use --env to separate configs per project.

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

sygmail-0.1.1.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sygmail-0.1.1-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file sygmail-0.1.1.tar.gz.

File metadata

  • Download URL: sygmail-0.1.1.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.3

File hashes

Hashes for sygmail-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7bf2b86e4be7e560085468f6839d545f5a0970a20446f68fbd88334282f9df7f
MD5 d8ebd2cc840432a2dbfd14a13a58dde7
BLAKE2b-256 6a2576ba32f6cb6930a7a2a856c13e2cf766cb4f4ffb99e4ae3cf8b82eb9840e

See more details on using hashes here.

File details

Details for the file sygmail-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: sygmail-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.3

File hashes

Hashes for sygmail-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2e768e71cb7a1c6a2d6a498173bb6037ecb508f813f118bcaaee76a9593eb2a3
MD5 d757af5aeda59c73a011b31cb7e7ffe1
BLAKE2b-256 c7762491b51eb53e55309ab7d6840b8cf2be413e62880e70d8d3025fe9b7ce7a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page