Created
October 5, 2024 02:03
-
-
Save kuc-arc-f/e88cd005321654d2ef71659c63cbb96f to your computer and use it in GitHub Desktop.
nodemailer , send example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import nodemailer from 'nodemailer'; | |
const GOOGLE_MAIL_USER = "[email protected]"; | |
const GOOGLE_MAIL_PASSWORD = "123"; | |
const TO_MAIL= "[email protected]"; | |
// | |
async function sendMail() { | |
// SMTPトランスポートの設定 | |
const transporter = nodemailer.createTransport({ | |
service: 'gmail', | |
auth: { | |
user: GOOGLE_MAIL_USER, // 送信者のメールアドレス | |
pass: GOOGLE_MAIL_PASSWORD // 送信者のメールパスワードまたはアプリパスワード | |
} | |
}); | |
// メールのオプション | |
const mailOptions = { | |
from: GOOGLE_MAIL_USER, | |
to: TO_MAIL, // 受信者のメールアドレス | |
subject: 'Test Email from Node.js, 2024-10-01 00:10', | |
text: 'Hello, this is a test email sent from Node.js using Nodemailer!' | |
}; | |
// メールの送信 | |
try { | |
const info = await transporter.sendMail(mailOptions); | |
console.log('Email sent: ' + info.response); | |
} catch (error) { | |
console.error('Error sending email:', error); | |
} | |
} | |
// | |
sendMail(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment