当我尝试通过 nodemailer 通过电子邮件发送验证链接时,Google 阻止了我的电子邮件

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

我在当前项目中使用 nodemailer 向我的用户发送验证链接,但它没有用。

我在当前项目中使用 nodemailer 向我的用户发送验证链接。当项目处于开发模式时,邮件已成功发送给用户,但是当我在 cyclic.sh 上部署我的 Web 应用程序时,邮件没有发送。

const nodemailer = require('nodemailer');
const jwt = require("jsonwebtoken");
const path = require("path");
if(process.env.NODE_ENV !== "production") {
    require('dotenv').config({ path: path.join(__dirname, "..", ".env") });
}

const transporter = nodemailer.createTransport({
    service: 'gmail',
    auth: {
        user: process.env.MAIL_ID,
        pass: process.env.MAIL_PASSWORD
    }
});

module.exports = {
    sendVerificationLink: async (id, email, name) => {
        const token = jwt.sign({
            data: { userid: id, name: name, email: email },
            exp: Math.floor(Date.now() / 1000) + (60 * 60) 
        }, process.env.ACCESS_TOKEN_SECRET);
        const mailOptions = {
            from: process.env.MAIL_ID,
            to: `${email}`,
            subject: "Verify your email",
            html: `
                    <p>Hi ${name}, please click on the following link to verify your email</p>
                    <a href = "http://${process.env.DOMAIN}/auth/verify/${token}">Verify your email</a>
                  `
        };
        await transporter.sendMail(mailOptions);
        return;
    }
}
node.js express gmail nodemailer
1个回答
0
投票

即使它不在同一个子域中,其他人也可以在

*.cyclic.sh
下托管站点。因此,由于过去人们可能滥用过该域,因此谷歌将该域标记为可疑并将电子邮件标记为垃圾邮件,如顶部的错误所示。

你最好的选择是创建你自己的域名,因为它没有滥用历史,所以它不应该被标记。

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