Skip to main content

dc-texter

Send an SMS text 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-texter

Or: add dc-texter 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 = "youremail@gmail.com"
outgoing_email_password = "aaaabbbbccccdddd"
sms_address_for_texts = "1112224444@msg.fi.google.com"

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 gmail address.
    • OUTGOING_EMAIL_PASSWORD: Set this to your application password.
    • SMS_ADDRESS_FOR_TEXTS: Set this to your phonenumber@your.provider.gateway

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_texter import send_text

message = "Testing text alerts from Python."

try:
    send_text(body=message)
    print(f"SUCCESS. Text sent: {message}")
except RuntimeError as e:
    print(f"ERROR:  Sending failed: {e}")

Metadata

Release files for dc-texter 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dc-texter 0.1.5
File Size Uploaded
dc_texter-0.1.5.tar.gz 8.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dc-texter 0.1.5
File Interpreter ABI Platform
dc_texter-0.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 15.7 kB

Release files / dc_texter-0.1.5.tar.gz

Download URL dc_texter-0.1.5.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
932e7deabe6798ccc3a831556dd96f95c34091ac1c3026e1cd0860f95bfc2c11
BLAKE2b-256 checksum
How to use checksums
98dc52fa1207681ebe4a514d729baf4118d6e2f26e804567d86c0624e7890236
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.11

Release files / dc_texter-0.1.5-py3-none-any.whl

Download URL dc_texter-0.1.5-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cf3c9e0428d26c0584abfc37545af74b258a9f3afefdc3e8481cd9cf010beb01
BLAKE2b-256 checksum
How to use checksums
62e34cc76025874d8df94cd91c0e32a6a64b5e0f23e6f22315b310ed7cea1791
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.11

Release history Release notifications | RSS feed

This release

0.1.5 This release

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page