- Rename directory keep-notes -> memento-note with all code references - Prisma: SQLite -> PostgreSQL (both app and MCP server schemas) - Sync MCP schema with main app (add missing fields, relations, indexes) - Delete 17 SQLite migrations (clean slate for PostgreSQL) - Remove SQLite dependencies (@libsql/client, better-sqlite3, etc.) - Fix MCP server: hardcoded Windows DB paths -> DATABASE_URL env var - Fix MCP server: .dockerignore excluded index-sse.js (SSE mode broken) - MCP Dockerfile: node:20 -> node:22 - Docker Compose: add postgres service, remove SQLite volume - Generate favicon.ico, icon-192.png, icon-512.png, apple-icon.png - Update layout.tsx icons and manifest.json for PNG icons - Update all .env files for PostgreSQL - Rewrite README.md with updated sections - Remove mcp-server/node_modules and prisma/client-generated from git tracking Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
65 lines
2.1 KiB
TypeScript
65 lines
2.1 KiB
TypeScript
import nodemailer from 'nodemailer';
|
|
import { getSystemConfig } from './config';
|
|
|
|
interface MailOptions {
|
|
to: string;
|
|
subject: string;
|
|
html: string;
|
|
}
|
|
|
|
export async function sendEmail({ to, subject, html }: MailOptions) {
|
|
const config = await getSystemConfig();
|
|
|
|
const host = config.SMTP_HOST || process.env.SMTP_HOST;
|
|
const port = parseInt(config.SMTP_PORT || process.env.SMTP_PORT || '587');
|
|
const user = (config.SMTP_USER || process.env.SMTP_USER || '').trim();
|
|
const pass = (config.SMTP_PASS || process.env.SMTP_PASS || '').trim();
|
|
const from = config.SMTP_FROM || process.env.SMTP_FROM || 'noreply@memento.app';
|
|
|
|
// Options de sécurité
|
|
const forceSecure = config.SMTP_SECURE === 'true'; // Forcé par l'admin
|
|
const isPort465 = port === 465;
|
|
// Si secure n'est pas forcé, on déduit du port (465 = secure, autres = starttls)
|
|
const secure = forceSecure || isPort465;
|
|
|
|
const ignoreCerts = config.SMTP_IGNORE_CERT === 'true';
|
|
|
|
const transporter = nodemailer.createTransport({
|
|
host: host || undefined,
|
|
port: port || undefined,
|
|
secure: secure || false,
|
|
auth: { user, pass },
|
|
// Force IPv4 pour éviter les problèmes de résolution DNS/Docker
|
|
family: 4,
|
|
// Force AUTH LOGIN pour meilleure compatibilité (Mailcow, Exchange) vs PLAIN par défaut
|
|
authMethod: 'LOGIN',
|
|
// Timeout généreux
|
|
connectionTimeout: 10000,
|
|
tls: {
|
|
// Si on ignore les certs, on autorise tout.
|
|
// Sinon on laisse les défauts stricts de Node.
|
|
rejectUnauthorized: !ignoreCerts,
|
|
// Compatibilité vieux serveurs si besoin (optionnel, activé si ignoreCerts pour maximiser les chances)
|
|
ciphers: ignoreCerts ? 'SSLv3' : undefined
|
|
}
|
|
} as any);
|
|
|
|
try {
|
|
await transporter.verify();
|
|
|
|
const info = await transporter.sendMail({
|
|
from: `"Memento App" <${from}>`,
|
|
to,
|
|
subject,
|
|
html,
|
|
});
|
|
|
|
return { success: true, messageId: info.messageId };
|
|
} catch (error: any) {
|
|
console.error("❌ Erreur SMTP:", error);
|
|
return {
|
|
success: false,
|
|
error: `Erreur envoi: ${error.message} (Code: ${error.code})`
|
|
};
|
|
}
|
|
} |