我写了一些代码来在我的 nodejs 应用程序中实现 nodemailer 来发送邮件。
我写了这段代码:
var express = require("express");
var router = express.Router();
var nodemailer = require("nodemailer");
/* GET contact page. */
router.get("/", function (req, res, next) {
res.render("contact", { title: "Contact" });
});
router.post("/send", function (req, res, next) {
var transporter = nodemailer.createTransport({
service: "Gmail",
auth: {
user: "MyEmailHere",
pass: "password",
},
tls: {
rejectUnauthorized: false
}
});
var mailOptions = {
from: "MyEmailHere",
to: "myOtherEmailId",
subject: "Website Submission",
text:
"You have a new submission with the following details...Name: " +
req.body.name +
" Email: " +
req.body.email +
" Message: " +
req.body.message,
html:
"<p> You got a new submission with the following details...</p><ul></ul><li>Name: " +
req.body.name +
"</li><li>Email: " +
req.body.email +
"</li><li>Message: " +
req.body.message +
"</li></ul>",
};
transporter.sendMail(mailOptions, function (error, info) {
if (error) {
console.log(error);
res.redirect("/");
} else {
console.log("Message Sent: " + info.response);
}
});
});
module.exports = router;
但我收到一条错误消息:“不接受用户名和密码。” 我应该使用我的真实密码吗?除了 Gmail 之外,nodemailer 是否还支持 Yahoomail?顺便说一下,我仍在学习并处于开发模式。一点帮助?
阿晨1998
哆啦的时光机
相关分类