# PRD: Enhance Email Sending Functionality with Format Support

This PRD builds upon the newly implemented email sending function (GPM-058) by adding support for different email formats (HTML and Plain Text).

### GPM-059: Add HTML Email Support
**Goal:** Enable sending emails with HTML content.
**Acceptance Criteria:**
- A new function `send_html_email(recipient, subject, html_content)` exists.
- This function successfully sends an email with the provided HTML content.
- The email is correctly rendered as HTML in email clients that support it.
- The email headers correctly specify the content type as `text/html`.
**Files:** `aiva/email/email_sender.py` (modify), `aiva/email/templates/html_email_template.html` (example)
**Spawns:** Implement styling for HTML emails.

### GPM-060: Add Plain Text Email Support
**Goal:** Enable sending emails with plain text content.
**Acceptance Criteria:**
- A new function `send_plain_text_email(recipient, subject, text_content)` exists.
- This function successfully sends an email with the provided plain text content.
- The email is correctly rendered as plain text in email clients.
- The email headers correctly specify the content type as `text/plain`.
**Files:** `aiva/email/email_sender.py` (modify)
**Spawns:** Implement email logging.

### GPM-061: Refactor Email Sending Function for Format Selection
**Goal:** Consolidate HTML and plain text sending into a single function with format selection.
**Acceptance Criteria:**
- A single function `send_email(recipient, subject, content, format='plain')` exists.
- The `format` parameter accepts 'plain' or 'html'.
- If format is 'plain', the email is sent as plain text.
- If format is 'html', the email is sent as HTML.
- The function handles invalid format parameters gracefully (e.g., raises an exception or defaults to plain text).
- The older `send_html_email` and `send_plain_text_email` functions are deprecated, but remain operational with a deprecation warning.
**Files:** `aiva/email/email_sender.py` (modify)
**Spawns:** Implement email attachments.

### GPM-062: Add Email Configuration Options
**Goal:** Allow users to configure email settings such as SMTP server and port.
**Acceptance Criteria:**
- Email settings (SMTP server, port, username, password, sender address) are configurable through a configuration file (e.g., `config.ini` or environment variables).
- The email sending function reads these settings from the configuration.
- Default values are provided if configuration is missing.
- Incorrect configuration values raise an exception.
**Files:** `aiva/config.py` (create), `aiva/email/email_sender.py` (modify)
**Spawns:** Implement email testing functionality.

### GPM-063: Implement Basic Email Error Handling
**Goal:** Improve the robustness of the email sending function by handling potential errors.
**Acceptance Criteria:**
- The email sending function catches exceptions that may occur during the sending process (e.g., SMTP connection errors, authentication errors).
- When an error occurs, a descriptive error message is logged.
- The function does *not* crash when an error occurs; it gracefully handles the exception and returns a boolean indicating success or failure.
**Files:** `aiva/email/email_sender.py` (modify)
**Spawns:** Implement email retry mechanism.

### GPM-064: Implement Email Template Loading
**Goal:** Load email templates from external files.
**Acceptance Criteria:**
- A function `load_email_template(template_name)` exists.
- This function loads the email template from a specified file (e.g., from a `templates` directory).
- The function returns the template content as a string.
- The email sending function can use loaded templates.
**Files:** `aiva/email/email_sender.py` (modify), `aiva/email/utils.py` (create), `aiva/email/templates/`
**Spawns:** Implement templating engine for dynamic email content.
