Nodemailer
npm install nodemailerimport nodemailer from "nodemailer";
export const transport = nodemailer.createTransport({ host: "smtp.spacepost.dev", port: 25976, secure: false, // STARTTLS: the connection is upgraded to TLS before login requireTLS: true, auth: { user: "spacepost", pass: process.env.SPACEPOST_API_KEY },});
await transport.sendMail({ from: '"Acme" <hello@acme.com>', to: ["user@example.com"], cc: "manager@example.com", subject: "Your invoice", text: "Invoice attached.", html: '<p>Invoice attached.</p><img src="cid:logo" />', attachments: [ { filename: "invoice.pdf", path: "./invoice.pdf" }, { filename: "logo.png", path: "./logo.png", cid: "logo" }, ], headers: { "X-SpacePost-Tags": "category=invoice, order_id=1042", "X-SpacePost-Scheduled-At": "in 1 hour", },});Poole Verbindungen bei hohem Volumen:
nodemailer.createTransport({ host: "smtp.spacepost.dev", port: 25976, secure: false, requireTLS: true, pool: true, maxConnections: 5, auth: { user: "spacepost", pass: process.env.SPACEPOST_API_KEY },});secure: false mit requireTLS: true bedeutet STARTTLS: Nodemailer verbindet sich unverschlüsselt und wechselt auf TLS, bevor dein API-Schlüssel gesendet wird, und bricht ab, wenn der Wechsel fehlschlägt. Implizites TLS (secure: true, Port 465) wird noch nicht angeboten.
Bevorzuge für neuen Code das Node.js SDK: Es gibt die id der E-Mail und aussagekräftigere Fehler zurück.