Node-nodemailer成功发送邮件

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

我有以下代码将新条目保存在数据库Mongo中,我想通过nodemailer发送电子邮件,以防成功“ res.status(201)”。我的代码应该放在哪里?

    register: (req, res, next) => {
    bcrypt.hash(req.body.password, 10)
        .then(hash => {
            const person= new Person({
                email: req.body.email,
                password: hash
            });
            person.save()
                .then(() => res.status(201).json({ message: "OK" }))
                .catch((error) => res.status(400).json({ message: error }))
        })
        .catch(error => res.status(500).json({ message: error }));
},

感谢您的帮助

node.js nodemailer
1个回答
0
投票

解决方案是:

register: (req, res, next) => {
bcrypt.hash(req.body.password, 10)
    .then(hash => {
        const person= new Person({
            email: req.body.email,
            password: hash
        });
        person.save()
            .then(() =>
               {
               res.status(201).json({ message: "OK" }))
               ... nodemailer here ...
               }
            .catch((error) => res.status(400).json({ message: error }))
    })
    .catch(error => res.status(500).json({ message: error }));

},

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