Skip to main content

A simple email alert utility for Python projects

Project description

dc-mailer

Send an email alert using Python and Gmail

Requirements

  • Python 3.11+ (required for reading toml files)
  • A configured Gmail Account (see below)

Step 1. Install this Module

Use pip install dc-mailer or add dc-mailer to your requirements.txt and install.

Step 2. Add .env.toml To your Python Project

Create a new .env.toml file in your Python project (or add these entries). Update the outgoing email address to your gmail address. We'll create a password below.

outgoing_email_host = "smtp.gmail.com"
outgoing_email_port = 587
outgoing_email_address = "your-email@gmail.com"
outgoing_email_password = "your-app-password"

Step 3. Add .env.toml To .gitignore

Ensure your secrets are not published with an entry in .gitignore:

.env.toml

Step 4. Gmail - Enable IMAP

  • Open Gmail.
  • Click Settings or ⚙️ in the top-right.
  • Then click "See all settings".
  • Navigate to "Forwarding and POP/IMAP".
  • Under "IMAP access", select "Enable IMAP".
  • Click "Save Changes".

Step 5. Gmail - Generate an App Password

If your account has 2FA enabled, you must generate an App Password:

  • Go to https://support.google.com/accounts/answer/185833?hl=en
  • Click on "Create and manage your app passwords".
  • Sign in and navigate to Account "Security" / "App Passwords"
  • Create an app password - name it (e.g., "PythonEmailAlerts").
  • Generate and copy the 16-character password.
  • Paste the 16-char as your password in .env.toml file.
    • Remove any spaces
    • Keep it private - ensure your .env.toml file is listed in .gitignore

Step 6. Import and Use in a Python Script

Once installed and your .env.toml file is ready, you can use it in your code.

from dc_mailer import send_mail

title = "Email from Data Analyst and Python Developer"
content = "Did you know the Python standard library enables emailing?"
recipient = "your.email@gmail.com"

try:
    send_mail(subject=title, body=content, recipient=recipient)
    print("SUCCESS: Email sent successfully.")
except RuntimeError as e:
    print(f"ERROR: Email sending failed: {e}")

Testing

To run this file locally for testing, fork & clone the repo, add .env.toml. Open the project repository in VS Code, open a PowerShell terminal and run

pytest
py dc_mailer\mailer.py

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

dc_mailer-0.1.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

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

dc_mailer-0.1.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file dc_mailer-0.1.0.tar.gz.

File metadata

  • Download URL: dc_mailer-0.1.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for dc_mailer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1f59d154b2257f92253cdcf619e9a646bf3ccf907c048c30735521fbba70df69
MD5 1a255d8e769ccdfd912732b6c55d051f
BLAKE2b-256 ced6292fd4c1237baa0d8d88b047b75fba5209ee3992ce66b018f0d3d49edbbb

See more details on using hashes here.

File details

Details for the file dc_mailer-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: dc_mailer-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for dc_mailer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9862f602ab686cbd2099ba0e76f168e51fe7bb5415874fdf575b920d1b2e5d54
MD5 5ff48b7b32304bbc9846e0affb23c3ec
BLAKE2b-256 13371bddc509a0dbf2d75be35b806afb8743f54208757d6e31badeb84cee042e

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