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

Run

pip install dc-mailer

Or: add dc-mailer to requirements.txt and install.


Step 2. Configure Application Settings

Local Development

For local development, we can configure our settings with a file. First, add .env.toml to .gitignore to keep it from being published. Then, create a .env.toml file in your project directory with the following.

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

GitHub Action Deployments

In a deployment environment like GitHub Actions, the .env.toml file won't be available. Instead, you'll need to set the configuration variables as environment variables.

First, add the following secrets to your GitHub repository:

  1. Navigate to your repository on GitHub.
  2. Click on Settings > Secrets and variables > Actions.
  3. Click on New repository secret and add the following secrets:
    • OUTGOING_EMAIL_HOST: Set this to "smtp.gmail.com".
    • OUTGOING_EMAIL_PORT: Set this to 587.
    • OUTGOING_EMAIL_ADDRESS: Set this to your email address (e.g., "your-email@gmail.com").
    • OUTGOING_EMAIL_PASSWORD: Set this to your application password.

Next, reference these secrets in your GitHub Actions workflow. For an example, see this deploy.yml.


Step 3. Configure Gmail

Enable IMAP

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

Generate an App Password

  • If you have 2-Step Verification enabled, create an app password for "dc-mailer".
  • Copy the 16-character password displayed.
  • Paste the 16-char as your password in .env.toml file. Remove spaces.
  • For detailed instructions, refer to Google's support page.

Step 4. 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}")

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.1.tar.gz (5.4 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.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dc_mailer-0.1.1.tar.gz
  • Upload date:
  • Size: 5.4 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.1.tar.gz
Algorithm Hash digest
SHA256 ff554a67a32fc8c61ac3003fdce3a0e124c31947f1800e4f82fb0a9bbcb7e353
MD5 1f6a070fb43acd296aa75cac63a915e1
BLAKE2b-256 3a35368cfbbf10437db230289fe59e1d6ccbcd620d24e53d0d1ca21e6005e797

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dc_mailer-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.8 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b3de35a05ff4e1d0310e890c3f0fcd0d762769548df457528d8f7971bb2530c7
MD5 c6ab0aa041b0f351d59b789c2f16140c
BLAKE2b-256 b4fdaad32d120ef8ec7899f3baeecf7174edd2f16da39fc1f5ccd236d3d83288

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