📜  发送电子邮件 sgMail - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:05.353000             🧑  作者: Mango

代码示例1
router.post(
    '/send-mail',
    AuthController.sendMail
)




async sendMail(req, res, next){

        try{
        let otp = generateOtp();

        const msg = {
            to: req.body.email,
            from: 'baldianupamdev@yopmail.com', // Change to your verified sender
            subject: 'Eye 1-1: Verify Your Login',
            text: 'Please enter the following OTP to verify your login : ' + otp,
            html: 'Please enter the following OTP to verify your login :' + otp + ' ',
        }

        //Send Email Here
        sgMail
            .send(msg)
            .then(() => {
                console.log('Email sent');
                return res.success({
                }, "Email Send Successfully"
                );

                // const userJson = user.toJSON();
                // ['password', 'authTokenIssuedAt', 'otp', 'emailToken', '__v'].forEach(key => delete userJson[key]);
                // userJson.isDefaultLocation = false;
                // return res.success({
                //     "language": req.headers['accept-language'],
                //     token,
                //     user: userJson,
                // }, "Registration Completed"
                // );

            })}
            catch (err) {
                console.log(err);
                return next(err)
            }
        }