为什么邮件没有像提到的那样发送到电子邮件id?

时间:2018-08-14 04:57:11

标签: javascript node.js

我正在尝试使用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

1 个答案:

答案 0 :(得分:1)

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

  

…伪造的SMTP服务,主要针对Nodemailer用户(但不仅限于此)。这是一个完全免费的反事务电子邮件服务,使消息永远不会传递。

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