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

Use pip install dc-texter or add dc-texter 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.
  • Update the sms address for texts to your number, using your carrier's gateway (see .env.example.toml or do a search).
  • We'll create an app password below.
# SMTP Email Configuration
outgoing_email_host = "smtp.gmail.com"
outgoing_email_port = 587
outgoing_email_address = "yourname@gmail.com"
outgoing_email_password = "aaaabbbbccccdddd"

# SMS Configuration
sms_address_for_texts = "1112224444@msg.fi.google.com"

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., "PythonTextAlerts").
  • 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_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}")

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_texter\texter.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_texter-0.1.2.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_texter-0.1.2-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dc_texter-0.1.2.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_texter-0.1.2.tar.gz
Algorithm Hash digest
SHA256 59ee24c32d5bce1529065facb50043e9c7cd6fefb308d8baea8c9ca971a50fa7
MD5 cb6eda8b471dc8f36e55edd1fc8445c9
BLAKE2b-256 0fa3bdb9ec4a48a1d2ebe8f4b8442e66def13d7cde947347c4b8f554b81fbfc4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dc_texter-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.7 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ab55198071bd2584babd2e77eddfe4a2548b30f5c1f064108cb1003b58df90f1
MD5 6f7594c4154b14dd83aadc7bf68db7e8
BLAKE2b-256 48c57ef6f50b068676081ba0bd251cc52cb8311953c4a343f3f5d0c8f43ac0ff

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