Skip to main content

A simple SMS text alert utility for Python projects

Project description

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}")

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_texter-0.1.3.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

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

dc_texter-0.1.3-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file dc_texter-0.1.3.tar.gz.

File metadata

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

File hashes

Hashes for dc_texter-0.1.3.tar.gz
Algorithm Hash digest
SHA256 99f82be39c70c077d562ae7a161cf77dc0104a5860eca3116d2e21cada71e8de
MD5 3d23b7b252ddf72cd5a0d6bacb3c6278
BLAKE2b-256 02f560d6649d51f0be8e9ccc04086568a0ce9e9b8dde600a9c01f81d3bd6abd4

See more details on using hashes here.

File details

Details for the file dc_texter-0.1.3-py3-none-any.whl.

File metadata

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

File hashes

Hashes for dc_texter-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 16feb3868513e4e881fd2151e2c12a948391f60f28d8488546ab3449d4932793
MD5 91e93262f1045c3e60850f38c1f7a64f
BLAKE2b-256 3c0dc6194529928f55de2bf14772f516b0d870aff7fc0b79ca3f720702acc4fd

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