Nodemailerのトランスポートを、ご利用のプロバイダー自身のサーバーではなく ゲートウェイの受信サーバーに向けてください。
const nodemailer = require("nodemailer");
const transporter = nodemailer.createTransport({
host: "smtp.adlerwacht.com", // /introduction/smtp-relay を参照
port: 587, // または465
secure: false, // ポート465の場合はtrue、587でSTARTTLSの場合はfalse
auth: {
user: "you@yourcompany.com",
pass: process.env.SMTP_PASSWORD,
},
});
await transporter.sendMail({
from: "you@yourcompany.com",
to: "recipient@example.com",
subject: "Test",
text: "Hello from the gateway.",
});
パスワードはソースコードに直接記載せず、環境変数から読み込んでください。
Nodemailerを直接利用している場合でも、それをベースにしたフレームワーク
(例えばNestJSのMailerModule)を利用している場合でも、変更内容は同じです
——変わるのは基盤となるトランスポートのオプションだけで、メッセージの
組み立て方や送信方法は変わりません。