首页 > 解决方案 > nodemailer不发送邮件,给出250 ok

问题描述

我整个下午都在处理这个问题,欢迎所有想法。我目前正在运行以下示例代码来定位问题:

router.get('/', function(req, res, next) {
let transporter = nodemailer.createTransport({
    host: "cpsrv14.misshosting.com",
    port: 587,
    secure: false,
    auth: {
        user: config.email.user,
        pass: process.env.EMAIL_PASS
    },
    tls: {
        rejectUnauthorized: false
    }
});

// verify connection configuration
transporter.verify(function(error, success) {
    if (error) {
        console.log(error);
    } else {
        console.log("Server is ready to take our messages");
    }
});

transporter.sendMail({
    from: '"Fred Foo " <foo@example.com>', // sender address
    to: 'christopher.rosenvall@gmail.com', // list of receivers
    subject: 'Hello ✔', // Subject line
    text: 'Hello world?', // plain text body
    html: '<b>Hello world?</b>' // html body
}).then(resp => {
    console.log('Message sent: %s', JSON.stringify(resp));
    res.status(200).json({
        success: true
    })
}).catch( err => {
    console.log(err);
    res.status(400)
});

});

应请求控制台给了我以下对我来说似乎没问题的信息:

Server is ready to take our messages

Message sent: {"accepted":["christopher.rosenvall@gmail.com"],"rejected":
[],"envelopeTime":84,"messageTime":403,"messageSize":603,"response":"250 OK id=1iFhm4-0004WG-
NM","envelope":{"from":"foo@example.com","to":["christopher.rosenvall@gmail.com"]},"messageId":"
<7f8f8aab-f900-1e8e-2cde-3da5ad2687ba@example.com>"}

GET / 200 762.254 ms - 16

我已经尝试过运行安全而不是运行安全,使用 tls 设置和不使用 - 只要我可以进行身份​​验证,似乎没有什么不同。

问题是电子邮件从未发送过,我尝试将其发送到一堆不同的电子邮件地址,但没有一个人收到电子邮件。

标签: node.jsreactjsnodemailer

解决方案


仔细检查您是否在选项中给予。我遇到了这个问题。就我而言,我没有在选项字段中提供。但是从:fromemail@mail.com 获得后一切正常


推荐阅读