Serverless‑Beispiel (Vercel/Node + Nodemailer) für /api/send
// api/send.js (Vercel)
import nodemailer from 'nodemailer';
export default async function handler(req, res){
if(req.method !== 'POST') return res.status(405).json({error:'Method not allowed'});
try {
const { to, subject, text } = req.body;
const { fileBase64, fileName } = req.body; // Base64 (data:application/pdf;base64,....)
if(!to || !fileBase64) return res.status(400).json({error:'missing to/file'});
const transporter = nodemailer.createTransport({
host: process.env.SMTP_HOST,
port: Number(process.env.SMTP_PORT || 587),
secure: false,
auth: { user: process.env.SMTP_USER, pass: process.env.SMTP_PASS }
});
await transporter.sendMail({
from: process.env.MAIL_FROM,
to, subject: subject || 'Signiertes Dokument',
text: text || 'Anbei das unterschriebene PDF.',
attachments: [{ filename: fileName || 'signed.pdf', content: fileBase64.split(',')[1], encoding: 'base64' }]
});
res.status(200).json({ ok: true });
} catch (e){
console.error(e);
res.status(500).json({error:'send failed'});
}
}
Umgebungsvariablen: SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASS, MAIL_FROM. Alternativ SendGrid/Mailgun/Postmark API verwenden.