我正在使用nodemailer收到来自注册表单的电子邮件。
这是我的表格
<form action="/registration" method="post">
<h3 class="text-center" style="font-family: 'champagne-limo';">Registration</h3>
<div class="long-border mb-4"></div>
<div class="form-group row">
<input class="form-control" style="font-family: 'champagne-limo';" type="text" id="email" placeholder="Email">
</div>
<div class="form-group row">
<input class="form-control" style="font-family: 'champagne-limo';" type="password" placeholder="Enter Password" required>
</div>
<div class="form-group row">
<input class="form-control" style="font-family: 'champagne-limo';" type="password" placeholder="Re-Enter Password" required>
</div>
<input class="create-accnt col-2" type="submit">
</form>`enter code here`
在我的app.js中我有这个
app.get("/registration", function(req,res){
res.render("registration.ejs")
});
app.post("/registration", function(req,res){
var transporter = nodemailer.createTransport({
service: 'yahoo',
auth: {
user: 'test@yahoo.com',
pass: 'Test123'
}
});
var mailOptions = {
from: 'Tester ✔ <test@gmail.com>',
to: 'test@gmail.com',
subject: 'Testing test ✔',
text: 'It works! ✔', //plaintext body
html: '<p>It works</p>'//rich text html body
};
//send mail with defined transport object
transporter.sendMail(mailOptions, function(error, info){
if(error){
console.log(error);
}else{
console.log('Message sent: ' + info.response);
}
});
})
当我在控制台中点击提交时,我的邮件客户端出错了。然后我在雅虎上创建了一个测试邮件并得到了同样的错误。我错过了什么?这看起来就像文档上的说明如何将它组合在一起。
答案 0 :(得分:0)
答案 1 :(得分:0)
示例代码 - 使用Yahoo的Nodemailer:
const yahoo_host = "smtp.mail.yahoo.com";
const email_smtp = nodemailer.createTransport({
host: yahoo_host,
auth: {
user: "someone@yahoo.com",
pass: "PASSWORD_HERE"
}
});