Nodemailer "连接ETIMEDOUT "与自定义域。

问题描述 投票:1回答:1

我在Node.js中做了一个忘记密码的后台路由,我试图使用nodemailer从我从namecheap.com购买的自定义域名发送邮件,同时发送邮件域名。我不确定是主机的问题,还是端口安全的问题,或者是 auth 的问题。然而,当我改变主机时,它给出了一个ECONREFUSED错误,所以我相信这部分是工作的。我的防火墙是(据我所知)被禁用的,我也重新启动了,但是因为Norton Antivirus控制了它,所以很难说。

这是我的代码,取自我后台的router.get路由。

完整的错误是 "连接ETIMEDOUT",然后是一个ip地址,最后是:587。

const transporter = createTransport({
        host: 'axotl.com',
        port: 587,
        secure: false,
        auth: {
            user: config.get('emailUser'),
            pass: config.get('emailPass')
        }
    });
    let resetLink = '';
    let authToken = '';
    await jwt.sign({ email: req.params.email }, config.get('JWTSecret'), { expiresIn: 10800000 }, (err, token) => {
        if (err) throw err;
        authToken += token;
    })
    resetLink = await `${config.get('productionLink')}/recipients/resetpassword/${authToken}`
    console.log(`resetlink : ${resetLink}`)
    const mailOptions = {
        from: '"Axotl Support" <[email protected]>',
        to: req.params.email,
        subject: "Forgot Password",
        text: `Hello ${req.name},\n\nHere is the password reset link you requested (expires in 3 hours): ${resetLink}\nIf you did not request this, please notify us at http://axotl.com/support\n\nThanks!\n-Axotl Support`
    }
    try {
        console.log('trycatch entered')
            // const verified = await transporter.verify()
            // console.log(`verified : ${verified}`)
        const res = await transporter.sendMail(mailOptions)
        console.log('email completed')
        console.log(res)

        res.json({ msg: "email sent" })
    } catch (err) {
        console.error(err.message);
        res.status(500).send("Server Error")
    }
node.js nodemailer
1个回答
0
投票

原来我用错了主机域名--服务并不直接在网站上托管电子邮件域名。我对这个具体部分不够了解。我把它改成了电子邮件主机,就可以了。

© www.soinside.com 2019 - 2024. All rights reserved.