Files
a04d484451 refactor(email): SES -> @bitbaum/mail-kit; drop @aws-sdk/client-ses (#178)
The playbook expected no SES call sites, but lib/email/service.ts is live
(consultations route sends welcome + admin mails through it), so a bare dep
removal would have broken the build. Instead the transport is swapped to the
fleet's mail layer:

- EmailService now sends via @bitbaum/mail-kit sendMail; the throw-on-failure
  contract is preserved for the catching caller
- Sender comes from RESEND_FROM (fleet SSOT) with conventionalFrom('Botsmann')
  fallback; FROM_EMAIL and NEXT_AWS_* reads deleted from email config paths
- @aws-sdk/client-ses removed; tests mock @bitbaum/mail-kit instead of SES,
  with a new failed-send assertion


Claude-Session: https://claude.ai/code/session_01WqKqMnHQHSmkGFfc5t7Rxn

Co-authored-by: Mao Nakamoto <41178744+maonakamoto@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-09-05 10:14:55 +00:00

46 lines
1.9 KiB
TypeScript

import { sendMail, fromAddress, conventionalFrom } from '@bitbaum/mail-kit';
import type { Customer } from '@/lib/schemas/customer';
import { logger } from '../logger';
export class EmailService {
private fromEmail: string;
private adminEmail: string;
constructor() {
// RESEND_FROM is the fleet-wide sender SSOT (read by mail-kit); the
// conventional fallback sends as botsmann@fleetcrown.orangecat.ch.
this.fromEmail = fromAddress() ?? conventionalFrom('Botsmann');
this.adminEmail = process.env.ADMIN_EMAIL || 'REDACTED_EMAIL';
}
async sendWelcomeEmail(customer: Customer): Promise<void> {
const result = await sendMail({
from: this.fromEmail,
to: customer.email,
subject: 'Welcome to Botsmann!',
text: `Hello ${customer.name},\n\nThank you for your interest in Botsmann! We've received your message and will get back to you soon.\n\nBest regards,\nThe Botsmann Team`,
});
if (!result.sent) {
// Preserve the old throw-on-failure contract — the caller catches.
logger.error('Failed to send welcome email:', result.error);
throw new Error(`Failed to send welcome email: ${result.error}`);
}
}
async sendAdminNotification(customer: Customer): Promise<void> {
const result = await sendMail({
from: this.fromEmail,
to: this.adminEmail,
subject: 'New Customer Registration',
text: `New customer registration:\n\nName: ${customer.name}\nEmail: ${customer.email}\nMessage: ${customer.message}\n\nPreferences:\n- Newsletter: ${customer.preferences.newsletter ? 'Yes' : 'No'}\n- Product Updates: ${customer.preferences.productUpdates ? 'Yes' : 'No'}`,
});
if (!result.sent) {
// Preserve the old throw-on-failure contract — the caller catches.
logger.error('Failed to send admin notification:', result.error);
throw new Error(`Failed to send admin notification: ${result.error}`);
}
}
}