gpt4 book ai didi

javascript - 为什么邮件没有发送到提到的电子邮件地址?

转载 作者:行者123 更新时间:2023-12-03 01:19:22 29 4
gpt4 key购买 nike

我正在尝试使用nodejs发送电子邮件。我使用了这个插件:https://nodemailer.com/about/,但我没有收到任何邮件。

我做错了什么?

这里是来自服务器的代码和日志:

var express = require('express'),
app = express(),
nodeMailer = require('nodemailer'),
PORT = process.env.PORT || 3000;


app.get('/', (req, res) => {
res.send('hello')
});


// Generate test SMTP service account from ethereal.email
// Only needed if you don't have a real mail account for testing
nodeMailer.createTestAccount((err, account) => {
// create reusable transporter object using the default SMTP transport
let transporter = nodeMailer.createTransport({
host: 'smtp.ethereal.email',
port: 587,
secure: false, // true for 465, false for other ports
auth: {
user: account.user, // generated ethereal user
pass: account.pass // generated ethereal password
}
});

// setup email data with unicode symbols
let mailOptions = {
from: '"naveen sharma" <naveen4sharma@airtel.com>', // sender address
to: 'naveen.nsit89@gmail.com', // list of receivers
subject: 'Hello ✔', // Subject line
text: 'Hello world?', // plain text body
html: '<b>Hello world?</b>' // html body
};

// send mail with defined transport object
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.log(error);
}
console.log('Message sent: %s', info.messageId);
// Preview only available when sending through an Ethereal account
console.log('Preview URL: %s', nodeMailer.getTestMessageUrl(info));

// Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>
// Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
});
});

app.listen(PORT, () => {
console.log('listing to ', PORT);
});

日志

[nodemon] restarting due to changes...
[nodemon] starting `node index.js`
listing to 3000
Message sent: <bf7fd7fb-ab76-7daf-e444-fb41b13a1080@airtel.com>
Preview URL: https://ethereal.email/message/W3Je0ho6KAyKJDkaW3Je1jX5zQzZ1TACAAAAARumoZhAa-nxhgOGHx1HBgA

最佳答案

您正在通过 Ethereal 发送消息,即:

… a fake SMTP service, mostly aimed at Nodemailer users (but not limited to). It's a completely free anti-transactional email service where messages never get delivered.

如果您想实际发送邮件,您需要向真正的电子邮件服务提供商支付帐户费用。

关于javascript - 为什么邮件没有发送到提到的电子邮件地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51833971/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com