startEmailListener (channels/email.ts)

owly · src/lib/channels/email.ts · typescript · MIT
email

Handles IMAP email listening, AI responses, and SMTP sending in a support system.

// Source: https://github.com/Hesper-Labs/owly | License: MIT | Copyright 2026 Owly
// Provided via justclaw.it.com; keep this notice with the code.
import Imap from "imap";
import { simpleParser, ParsedMail } from "mailparser";
import nodemailer from "nodemailer";
import { prisma } from "@/lib/prisma";
import { chat, createNewConversation } from "@/lib/ai/engine";
import { escapeHtml, sanitizeEmailSubject } from "@/lib/security";
import { logger } from "@/lib/logger";
import { resolveCustomer } from "@/lib/customer-resolver";

interface EmailConfig {
  imapHost: string;
  imapPort: number;
  imapUser: string;
  imapPass: string;
  smtpHost: string;
  smtpPort: number;
  smtpUser: string;
  smtpPass: string;
  smtpFrom: string;
}

let imapConnection: Imap | null = null;
let isListening = f

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key