# Email System

## Email System Documentation

The Treem DAO platform includes a comprehensive email management system that allows administrators to configure email templates, manage SMTP settings, send bulk emails, and track email analytics.

### Overview

The email system provides:

* **Template Management**: Create and manage reusable email templates
* **SMTP Configuration**: Configure custom email providers or use the default Resend service
* **Bulk Email Sending**: Send emails to multiple users or user groups
* **Email Analytics**: Track delivery rates, opens, and performance metrics
* **User Preferences**: Allow users to control their email subscription preferences

### System Architecture

The email system consists of:

* **Frontend Components**: Admin interface for email management
* **Edge Function**: `enhanced-email-service` for processing and sending emails
* **Database Tables**: Storage for templates, configurations, logs, and preferences
* **Default Provider**: Resend service integration for reliable email delivery

### Quick Start

#### For Administrators

1. Navigate to **Admin Dashboard → Settings → Email System**
2. Start with the **Templates** tab to create your first email template
3. Optionally configure custom SMTP in the **Configuration** tab
4. Use **Bulk Send** to send emails to users
5. Monitor performance in **Analytics** and **Recent** tabs

#### For Users

1. Go to **Profile → Email Preferences**
2. Configure which types of emails you want to receive
3. Toggle notifications for governance, transactions, security, etc.

### Table of Contents

* Template Management
* SMTP Configuration
* Bulk Email Sending
* Email Analytics
* User Preferences
* API Reference
* Troubleshooting

### Default Email Provider

The system uses **Resend** as the default email service provider, which offers:

* High delivery rates
* Built-in spam protection
* Reliable infrastructure
* Easy integration

When no custom SMTP configuration is active, all emails are sent through Resend.

### Security Features

* **Row Level Security (RLS)**: All email data is protected with proper access controls
* **Admin-only Access**: Email management features are restricted to administrators
* **User Privacy**: Users can control their email preferences independently
* **Secure Storage**: SMTP credentials are securely stored in Supabase

### Getting Help

If you encounter issues with the email system:

1. Check the Troubleshooting Guide
2. Review email logs in the **Recent** tab
3. Verify your SMTP configuration if using custom providers
4. Ensure your Resend API key is properly configured


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.treem.io/treem-dao/email-system.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
