Metadata-Version: 2.2
Name: dc_mailer
Version: 0.1.5
Summary: A simple email alert utility for Python projects
Author-email: Denise Case <denisecase@gmail.com>
License: MIT License
        
        Copyright (c) 2025 Denise Case
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/denisecase/dc-mailer
Project-URL: Repository, https://github.com/denisecase/dc-mailer
Project-URL: BugTracker, https://github.com/denisecase/dc-mailer/issues
Keywords: email,alert,notification
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Requires-Dist: twine; extra == "dev"
Requires-Dist: build; extra == "dev"

# 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 = "youremail@gmail.com"
outgoing_email_password = "aaaabbbbccccdddd"
```

### 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](https://github.com/denisecase/kafka-producer-earthquake/blob/main/.github/workflows/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](https://support.google.com/accounts/answer/185833?hl=en).

---

## 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. 

```python
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 = "youremail@gmail.com"

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