Metadata-Version: 2.4
Name: email_notify
Version: 1.1.0
Summary: Email notifications when a code block or function finishes or ends unexpectedly.
Author: Chao-Ning Hu
License: MIT License
        
        Copyright (c) 2023 Chao-Ning Hu
        
        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.
        
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: cryptography
Dynamic: license-file

# Email Notify

Email notifications when a code block or function finishes or ends unexpectedly.

Use SMTP service.

## Configuration

Before using, you need to configure your email account and SMTP server.

```python
import email_notify

# Set email address and application password (will be encrypted and saved if save=True)
email_notify.auth(save=True)

# Set SMTP server host and port (will be saved if save=True)
email_notify.smtp(save=True)
```

Configuration is saved in `$HOME/.email_notify.config`. Call `forget()` to remove the saved configuration.

## Usage

You can use `email_notify` in three ways: 

- As a context manager (recommended)
- As a decorator
- Calling `email_notify.send(subject, message, recipient)` directly

### Context Manager (recommended)

```python
import email_notify

recipient = 'user@example.com'

with email_notify.context(recipient, task_name='Task'):
    print('Running some tasks...')
    # some tasks
```

### Decorator

```python
import email_notify

recipient = 'user@example.com'

@email_notify.decorator(recipient)
def my_task():
    print('Running some tasks...')
    # some tasks

my_task()
```

### Direct Send

```python
import email_notify

recipient = 'user@example.com'

try:
    print('Running some tasks...')
    # some tasks
except Exception as e:
    subject = 'Task Failed'
    message = f'The task failed with error:\n{e}'
    email_notify.send(subject, message, recipient)
else:
    subject = 'Task Completed'
    message = f'The task finished successfully.\nResult: {result}'
    email_notify.send(subject, message, recipient)
```

## Installation

```bash
pip install email_notify
```

## Requirements

- cryptography

## Note

Make sure you know your SMTP service host and port before configuring.

Known SMTP service hosts and ports (updated 2025-6-8):

| Provider | SMTP Host   | SMTP Port  |
| -------- | ----------- | ---------- |
| QQ Mail  | smtp.qq.com | 465 or 587 |

For other providers, please refer to your email service documentation or contact your administrator.
