Files
clm-system/PLANNING/smtp.md

138 lines
3.8 KiB
Markdown

# Sendria SMTP Integration Guide
## Overview
Sendria (formerly MailTrap) is a development SMTP server that catches emails and displays them in a web interface instead of sending them to real recipients. Perfect for development/testing environments.
## Installation
Sendria is a standalone SMTP server application, not a Python package. Install it separately:
**Using uv pip (recommended for Python environments):**
```bash
uv pip install sendria
```
**Using Docker (most reliable):**
```bash
docker pull ghcr.io/mmbesar/sendria-container:latest
docker run -d \
--name sendria \
-p 1025:1025 \
-p 1080:1080 \
ghcr.io/mmbesar/sendria-container:latest
```
## Quick Start
1. **Start Sendria server:**
```bash
sendria --db mails.sqlite
```
2. **Access the web interface:**
- SMTP server: `smtp://127.0.0.1:1025`
- Web interface: `http://127.0.0.1:1080`
## Configuration
### Update Environment Variables
Update your `.env` file to use Sendria:
```bash
# Email Configuration for Sendria (development)
EMAIL_SMTP_SERVER=127.0.0.1
EMAIL_SMTP_PORT=1025
EMAIL_USERNAME=
EMAIL_PASSWORD=
RECIPIENT_EMAIL=admin@example.com
```
### Enable Email Sending in Agent
In `src/clm_system/agent.py`, modify the `send_email_report` method:
```python
def send_email_report(self, expiring_contracts: list[ContractAlert], conflicts: list[ContractAlert]):
"""Send email report with scan results"""
try:
msg = MIMEMultipart()
msg['From'] = self.sender_email
msg['To'] = self.recipient_email
msg['Subject'] = f"CLM Daily Report - {datetime.now().strftime('%Y-%m-%d')}"
# Create email body
body = self.create_email_body(expiring_contracts, conflicts)
msg.attach(MIMEText(body, 'plain'))
# Send email via Sendria
server = smtplib.SMTP(self.smtp_server, self.smtp_port)
# No TLS or authentication needed for Sendria
server.send_message(msg)
server.quit()
logger.info("Email report sent via Sendria")
except Exception as e:
logger.error(f"Error sending email report: {e}")
```
## Testing
1. **Start Sendria:**
```bash
sendria --db mails.sqlite
```
2. **Run your CLM system:**
```bash
streamlit run app.py
```
3. **Trigger a scan** or wait for scheduled scan
4. **Check captured emails** at `http://127.0.0.1:1080`
## Sendria Features
- **Email Catching**: Captures all emails sent to SMTP port 1025
- **Web Interface**: View emails in browser at port 1080
- **No Authentication**: Simple setup without credentials
- **SQLite Storage**: Emails persist in `mails.sqlite`
- **WebSocket Support**: Real-time email updates
- **API Access**: RESTful API for programmatic access
## API Endpoints
- `GET /api/messages/` - List all emails
- `GET /api/messages/{id}.json` - Email metadata
- `GET /api/messages/{id}.plain` - Plain text content
- `GET /api/messages/{id}.html` - HTML content
- `GET /api/messages/{id}.eml` - Download as EML file
## Production vs Development
- **Development**: Use Sendria (catches emails locally)
- **Production**: Use Gmail SMTP or other real SMTP service
**Important**: Sendria is only for development/testing. Never use it in production environments.
## Docker Alternative (Recommended)
```bash
docker pull ghcr.io/mmbesar/sendria-container:latest
docker run -d \
--name sendria \
-p 1025:1025 \
-p 1080:1080 \
ghcr.io/mmbesar/sendria-container:latest
```
Docker is the recommended approach as it doesn't require system-wide Python package installation.
## Common Issues
1. **Port already in use**: Kill existing process on port 1025 or 1080
2. **Can't see emails**: Check firewall settings and ensure ports are open
3. **Emails not sending**: Verify SMTP settings in your `.env` file
4. **Sendria not found**: Ensure it's installed with `uv pip install sendria`