Add multi-account support and CORS/logging middleware
- Add garfield, sales, leads, founder accounts to IMAP and SMTP configs - Refactor fetcherpay config into shared helper functions - Add CORS middleware with wildcard origin - Add request logging middleware and MCP session lifecycle logs - Include package-lock.json and add @types/cors dependency Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
92
src/smtp.ts
92
src/smtp.ts
@@ -1,34 +1,54 @@
|
||||
import nodemailer from 'nodemailer';
|
||||
import type { Account } from './imap.js';
|
||||
|
||||
function getSmtpTransport(account: Account = 'yahoo') {
|
||||
if (account === 'fetcherpay') {
|
||||
return nodemailer.createTransport({
|
||||
host: process.env['FETCHERPAY_SMTP_HOST'] ?? 'mail.fetcherpay.com',
|
||||
port: parseInt(process.env['FETCHERPAY_SMTP_PORT'] ?? '30587'),
|
||||
secure: false, // STARTTLS
|
||||
auth: {
|
||||
user: process.env['FETCHERPAY_EMAIL']!,
|
||||
pass: process.env['FETCHERPAY_PASSWORD']!,
|
||||
},
|
||||
tls: { rejectUnauthorized: false }, // self-signed cert
|
||||
});
|
||||
}
|
||||
const FETCHERPAY_SMTP_HOST = process.env['FETCHERPAY_SMTP_HOST'] ?? 'mail.fetcherpay.com';
|
||||
const FETCHERPAY_SMTP_PORT = parseInt(process.env['FETCHERPAY_SMTP_PORT'] ?? '30587');
|
||||
|
||||
function fetcherpaySmtpTransport(user: string, pass: string) {
|
||||
return nodemailer.createTransport({
|
||||
host: 'smtp.mail.yahoo.com',
|
||||
port: 587,
|
||||
secure: false,
|
||||
auth: {
|
||||
user: process.env['YAHOO_EMAIL']!,
|
||||
pass: process.env['YAHOO_APP_PASSWORD']!,
|
||||
},
|
||||
host: FETCHERPAY_SMTP_HOST,
|
||||
port: FETCHERPAY_SMTP_PORT,
|
||||
secure: false, // STARTTLS
|
||||
auth: { user, pass },
|
||||
tls: { rejectUnauthorized: false },
|
||||
});
|
||||
}
|
||||
|
||||
function getSmtpTransport(account: Account = 'yahoo') {
|
||||
switch (account) {
|
||||
case 'fetcherpay':
|
||||
return fetcherpaySmtpTransport(process.env['FETCHERPAY_EMAIL']!, process.env['FETCHERPAY_PASSWORD']!);
|
||||
case 'garfield':
|
||||
return fetcherpaySmtpTransport(process.env['GARFIELD_EMAIL']!, process.env['GARFIELD_PASSWORD']!);
|
||||
case 'sales':
|
||||
return fetcherpaySmtpTransport(process.env['SALES_EMAIL']!, process.env['SALES_PASSWORD']!);
|
||||
case 'leads':
|
||||
return fetcherpaySmtpTransport(process.env['LEADS_EMAIL']!, process.env['LEADS_PASSWORD']!);
|
||||
case 'founder':
|
||||
return fetcherpaySmtpTransport(process.env['FOUNDER_EMAIL']!, process.env['FOUNDER_PASSWORD']!);
|
||||
default:
|
||||
return nodemailer.createTransport({
|
||||
host: 'smtp.mail.yahoo.com',
|
||||
port: 587,
|
||||
secure: false,
|
||||
auth: {
|
||||
user: process.env['YAHOO_EMAIL']!,
|
||||
pass: process.env['YAHOO_APP_PASSWORD']!,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function getSenderEmail(account: Account = 'yahoo'): string {
|
||||
return account === 'fetcherpay'
|
||||
? process.env['FETCHERPAY_EMAIL']!
|
||||
: process.env['YAHOO_EMAIL']!;
|
||||
const emailMap: Record<Account, string> = {
|
||||
yahoo: process.env['YAHOO_EMAIL'] ?? '',
|
||||
fetcherpay: process.env['FETCHERPAY_EMAIL'] ?? '',
|
||||
garfield: process.env['GARFIELD_EMAIL'] ?? '',
|
||||
sales: process.env['SALES_EMAIL'] ?? '',
|
||||
leads: process.env['LEADS_EMAIL'] ?? '',
|
||||
founder: process.env['FOUNDER_EMAIL'] ?? '',
|
||||
};
|
||||
return emailMap[account] ?? '';
|
||||
}
|
||||
|
||||
export async function sendEmail(
|
||||
@@ -55,17 +75,21 @@ export async function createDraft(
|
||||
): Promise<string> {
|
||||
const { ImapFlow } = await import('imapflow');
|
||||
|
||||
const imapConfig = account === 'fetcherpay'
|
||||
? {
|
||||
host: process.env['FETCHERPAY_IMAP_HOST'] ?? 'mail.fetcherpay.com',
|
||||
port: parseInt(process.env['FETCHERPAY_IMAP_PORT'] ?? '30993'),
|
||||
secure: true,
|
||||
auth: {
|
||||
user: process.env['FETCHERPAY_EMAIL']!,
|
||||
pass: process.env['FETCHERPAY_PASSWORD']!,
|
||||
},
|
||||
tls: { rejectUnauthorized: false },
|
||||
}
|
||||
const fetcherpayImapBase = {
|
||||
host: process.env['FETCHERPAY_IMAP_HOST'] ?? 'mail.fetcherpay.com',
|
||||
port: parseInt(process.env['FETCHERPAY_IMAP_PORT'] ?? '30993'),
|
||||
secure: true,
|
||||
tls: { rejectUnauthorized: false },
|
||||
};
|
||||
const fetcherpayImapAccounts: Partial<Record<Account, { user: string; pass: string }>> = {
|
||||
fetcherpay: { user: process.env['FETCHERPAY_EMAIL']!, pass: process.env['FETCHERPAY_PASSWORD']! },
|
||||
garfield: { user: process.env['GARFIELD_EMAIL']!, pass: process.env['GARFIELD_PASSWORD']! },
|
||||
sales: { user: process.env['SALES_EMAIL']!, pass: process.env['SALES_PASSWORD']! },
|
||||
leads: { user: process.env['LEADS_EMAIL']!, pass: process.env['LEADS_PASSWORD']! },
|
||||
founder: { user: process.env['FOUNDER_EMAIL']!, pass: process.env['FOUNDER_PASSWORD']! },
|
||||
};
|
||||
const imapConfig = fetcherpayImapAccounts[account]
|
||||
? { ...fetcherpayImapBase, auth: fetcherpayImapAccounts[account]! }
|
||||
: {
|
||||
host: 'imap.mail.yahoo.com',
|
||||
port: 993,
|
||||
|
||||
Reference in New Issue
Block a user