diff --git a/package.json b/package.json index aa1c7deb0adb6e6aea5a1380426189ac24eee7a7..f90cb796b22daf46f662a0a475dc3c149062c2a5 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ }, "dependencies": { "guess": "^1.0.2", + "nodemailer": "^6.9.3", "vue": "^3.2.37" }, "devDependencies": { diff --git a/sendMail.js b/sendMail.js index 3d560e86791577a010f74fd5ae125dc76de5f400..b60c21a0bd6b9e7c44516fe2590fed50e4da94a5 100644 --- a/sendMail.js +++ b/sendMail.js @@ -1,11 +1,40 @@ -function sendMail () { - // 收件人邮箱 - const toEmail = 'example@mail.com'; - // 邮件主题 - const subject = 'Hello, world!'; - // 邮件内容 - const content = 'This is a test email.'; - - // 调用发送邮件的API - sendEmailAPI(toEmail, subject, content); -} +// 引入 nodemailer 模块 +const nodemailer = require('nodemailer'); + +// 定义发送邮件的函数 +function sendMail() { + // 设置邮件的收件人,主题和内容 + const recipient = 'admin@aresn.com'; + const subject = 'Test email'; + const message = 'This is a test email'; + + // 创建一个用于发送邮件的 transporter,这里使用的是 Gmail 服务 + const transporter = nodemailer.createTransport({ + service: 'gmail', + auth: { + user: 'your-email@gmail.com', // 你的 Gmail 邮箱 + pass: 'your-email-password' // 你的 Gmail 邮箱密码 + } + }); + + // 设置邮件的选项,包括发件人,收件人,主题和内容 + const mailOptions = { + from: 'your-email@gmail.com', // 你的 Gmail 邮箱 + to: recipient, + subject: subject, + text: message + }; + + // 调用 transporter 的 sendMail 方法发送邮件,根据发送结果输出日志 + transporter.sendMail(mailOptions, function (error, info) { + if (error) { + console.log(error); + return false; // 发送失败,返回 false + } else { + console.log('Email sent: ' + info.response); + return true; // 发送成功,返回 true + } + }); +} + +sendMail(); \ No newline at end of file