JavaScript Contact Forms Node.js - Tutorial 2026
Node、React、React Native、Koa、Express、Fastify、Nodemailer SMTP を使用して JavaScript 連絡フォームを作成し、送信します。
著者
Tiamati Email チーム
出版
3/1/26
読む時間
5分未満
インストールと要件
nodemailer npm 依存関係をインストールする必要があります:
npm install nodemailer
ソースコードと例
この例では、Nodemailer ライブラリとその公式スポンサー Forward Email を使用して、送信メールの送信とプレビューを行います。
送信メールを送るには パスワードを生成 する必要があります – ぜひ当社の カスタムドメイン SMTP でメールを送信するガイド に従ってください。
// app.js
import nodemailer from 'nodemailer';
const transporter = nodemailer.createTransport({
host: 'smtp.forwardemail.net',
port: 465,
secure: true,
auth: {
// TODO: 以下の `user` と `pass` の値を置き換えてください:
// <https://forwardemail.net/guides/send-email-with-custom-domain-smtp>
user: 'you@example.com',
pass: '****************************'
},
});
await transporter.sendMail({
from: 'you@example.com',
to: 'user@gmail.com',
subject: 'hello world',
html: '<h1>hello world</h1>'
});
アプリを実行してメールを送信します:
node app
次に、マイアカウント → メール にアクセスして、リアルタイムのメール配信状況、メール配信ログ、HTML/プレーンテキスト/添付ファイルのプレビューを確認できます。
P.S. 🎉 また、ブラウザや iOS シミュレーターでメールをプレビュー したり、Node.js でメールテンプレートを作成 したりすることもできます。