数据命令失败:421 4.3.0 临时系统问题。请稍后再试 (10) - gsmtp

Data command failed: 421 4.3.0 Temporary System Problem. Try again later (10) - gsmtp

提问人:Inaara Kalani 提问时间:5/27/2022 更新时间:10/24/2022 访问量:2905

问:

我已经在Firebase上部署了一个HTTPS函数,当我尝试批量发送电子邮件时,我总是收到此错误。我正在使用 nodemailer 池发送电子邮件。

错误:数据命令失败:421 4.3.0 临时系统问题。请稍后再试 (10) - gsmtp

客户端代码:

export const sendEmails = async () => {
    // Fetch All Users
    let users = []
    let data = await db.collection('users')

    data.forEach(e => {
        let data = e.data()
        let email = data['email']
        users.push({ email })
    })

    // Divide users into multiple batches of 25
    let batches = [[]], num = 0, batchSize = 25

    Promise.all(users.map(batch => {
        if (batches[num].length < batchSize) {
            batches[num].push(batch)
        } else {
            batches.push([batch])
            num++
        }
    }))

    // Send Email Request for each batch with some cooldown time. 
    Promise.all(batches.map((batch, index) => {
        setTimeout(async () => {
            await sendBroadcast(batch)
        }, 2000 * index)
    }))
}

export const sendBroadcast = async (users) => {
    const url = base + "sendBroadcast?"
    const body = JSON.stringify({ users })
    return await fetch(url, { method: "POST", body })
}

服务器端代码:

let transporter = nodemailer.createTransport({
    service: 'gmail',
    pool: true,
    maxConnections: 20,
    maxMessages: 500,
    auth: {
        user: 'SOME EMAIL',
        pass: 'SOME PASSWORD',
    },
})

exports.sendBroadcast = functions.runWith({ timeoutSeconds: 540, memory: '2GB' }).https.onRequest((req, res) => {
    cors(req, res, () => {
        const body = JSON.parse(req.body)
        const users = body.users

        console.log('info', 'Send email to ' + users.length + ' users')

        users.forEach(function (to, index) {
            var msg = {
                from: 'SOME EMAIL',
                to: to.email,
                subject: "SUBJECT",
                html: "<h2> SOME HTML </h2>",
            }

            return transporter.sendMail(msg, (erro, info) => {
                if (erro) {
                    console.log('error', erro.message, 'failed to send to ' + email)
                    return res.status(500).send(erro.toString())
                }
                return res.send('sent')
            })

        })
    })
})

这是因为 gmail 限制了每天的电子邮件数量吗?我在某处读到,如果我在每封电子邮件后添加冷却时间,它会起作用,我也尝试过,但我收到“在建立安全 TLS 连接之前客户端网络套接字断开连接”错误。以下是该问题的 Stack Overflow 线程: 通过 Nodemailer 发送批量电子邮件时,Firebase 函数出现错误“客户端网络套接字在建立安全 TLS 连接之前断开连接”

node.js reactjs google-cloud-functions 服务器端 节点邮件

评论

0赞 Sandeep Vokkareni 5/27/2022
你提到过这些链接吗?stackoverflow.com/questions/61633032/...stackoverflow.com/questions/64060781/......
0赞 Inaara Kalani 5/30/2022
是的,我有@SandeepVokkareni。正如你在我的代码中看到的,我使用了池化。正如我也提到的,我添加了冷却时间并遇到了不同的错误。我也在我的问题中添加了 Stack Overflow 的链接。
0赞 Sandeep Vokkareni 5/31/2022
您是否检查了本文的电子邮件发送限制以及Gmail SMTP错误和代码
0赞 Inaara Kalani 5/31/2022
是的,我有。这篇文章没有为我的问题@SandeepVokkareni提供解决方案。如果可以的话,请提供答案,因为简单地分享链接是没有帮助的。
0赞 paulsm4 10/24/2022
这回答了你的问题吗?Gmail SMTP错误 - 临时阻止?

答: 暂无答案