Email Channel

Email Outreach

AI-generated personalized emails sent through Resend, with automatic content generation powered by OpenRouter (Gemini 2.0 Flash).

How It Works

Email is the simplest channel -- it runs entirely within the Next.js dashboard (no external Python service needed). Emails can be sent manually from the dashboard or automatically through campaign execution.

AI Generation

Gemini 2.0 Flash generates personalized subject lines and body text

Resend Delivery

High-deliverability email API with tracking

Custom Sender

Configure from address, reply-to, and sender name per org

Email API Endpoints

POST/api/dashboard/email/send
POST/api/dashboard/email/generate
POST/api/dashboard/email/test
GET/api/dashboard/email/messages

AI Email Generation

The email generation endpoint uses OpenRouter (Gemini 2.0 Flash) to create personalized emails based on the lead information and selected script.

Generation Flow
User opens Email page in dashboard
    |
    |  Fills in lead name, company, selects script, email type
    v
POST /api/dashboard/email/generate
    |
    |  Load script content from DB
    |  Load voice config (language, personality)
    |  buildEmailPrompt() -> Build prompt template
    v
OpenRouter API (Gemini 2.0 Flash):
    |  Generate personalized email subject + body
    |  Parse JSON response: { "subject": "...", "body": "..." }
    v
Dashboard: Returns generated email for user review
    |
    |  User edits and clicks "Send"
    v
POST /api/dashboard/email/send
    |  Resend API sends the email
    |  Result logged to messages table

The system supports three email types for different stages of the outreach funnel:

initial

First contact email

followup

Follow-up after no reply

final

Last attempt before closing

Email Configuration

Email sender settings are stored in the channel_configs table per organization. Configure these from the dashboard settings.

Email Channel Config
{
  "channel": "email",
  "config": {
    "fromEmail": "sales@yourdomain.com",
    "fromName": "Sales Team",
    "replyTo": "sales@yourdomain.com"
  }
}

If no email config is set, the default sender is noreply@projectnoir.xyz.

Campaign Integration

During campaign execution, the email channel is typically the last priority (after Telegram and voice) since it has the lowest response rate. The campaign executor handles email automatically:

  1. Check if lead has an email address
  2. Build a personalized AI prompt using the campaign script
  3. Send via Resend API with the org's configured sender
  4. Log the result to the messages table
  5. Apply a 3-second inter-lead delay

Message Statuses

pending
sent
delivered
read
replied
failed