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", },});발송량이 많으면 연결을 풀링하세요.
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와 requireTLS: true는 STARTTLS를 뜻합니다. Nodemailer는 평문으로 연결한 뒤 API 키를 보내기 전에 TLS로 업그레이드하며, 업그레이드에 실패하면 진행하지 않습니다. 암시적 TLS(secure: true, 포트 465)는 아직 제공되지 않습니다.
새 코드에서는 이메일 id와 더 풍부한 오류를 반환하는 Node.js SDK를 권장합니다.