使用Nodemailer通过Hostinger批量发邮件遇投递失败问题求助
批量发送邮件时,前10封正常发送,后续出现投递失败错误
尝试向超过50个邮箱的列表发送邮件时,前约10封可正常发送,但一段时间后出现投递失败错误。错误提示如下:
您的邮件未送达,因为目标邮件系统出于安全或策略原因拒绝了您的邮件。例如,该邮箱地址可能仅接受特定发件人的邮件,或不接受特定类型的邮件(如超过特定大小的邮件)。
请联系收件人(例如通过电话),并与他们及其邮件管理员合作,确定是什么策略或设置阻止了您的邮件,以及您应采取什么措施确保未来的邮件不会被拒收。
以下是我的代码:
const path = require("path"); const nodemailer = require("nodemailer"); const hbs = require("nodemailer-express-handlebars"); require('dotenv').config(); // const { mail_list } = require("./csvjson"); const { mail } = require("./testing"); const filteredMail = mail; const sendMail = (name, email, indx) => { return new Promise((resolve, reject) => { try { const transporter = nodemailer.createTransport({ host: process.env.EMAIL_SERVICE, port: parseInt(process.env.EMAIL_PORT), secure: parseInt(process.env.EMAIL_PORT) == 465, secureConnection: false, tls: { ciphers: "SSLv3", }, requireTLS: true, auth: { user: process.env.EMAIL_USER, pass: process.env.EMAIL_PASSWORD, }, pool: true, connectionTimeout: 10000, maxConnections: 1, // Use one connection at a time maxMessages: 3, // Send a max of 3 messages per connection // logger: true, // debug: true }); const handlebarOptions = { viewEngine: { extName: ".handlebars", partialsDir: path.resolve("./views"), defaultLayout: false, }, viewPath: path.resolve("./views"), extName: ".handlebars", }; transporter.use("compile", hbs(handlebarOptions)); const mailOptions = { from: process.env.EMAIL_USER, to: email, subject: "Ok", template: "email", context: { title: "Ok", email: email, name: name, } }; transporter.sendMail(mailOptions, (error, info) => { if (error) { console.error(`Error sending email: ${indx}:`, error.message); reject(error); } else { console.log(`Success: ${indx} : ${email}`); resolve(info); } }); } catch (error) { console.error(`Error setting up email: ${indx}:`, error.message); reject(error); } }); }; const sendAllMails = (indx = 0) => { if (indx < filteredMail.length) { sendMail(filteredMail[indx].Name, filteredMail[indx].Email, indx) .then(() => { setTimeout(() => { sendAllMails(indx + 1); }, 15000); // 5000 milliseconds = 5 seconds }) .catch(() => { setTimeout(() => { sendAllMails(indx); // Retry the same index }, 180000); // 180000 milliseconds = 3 min }); } }; sendAllMails();
我的环境配置如下:
EMAIL_SERVICE = "smtp.hostinger.com" EMAIL_PORT = 465 EMAIL_USER = "email" EMAIL_PASSWORD = "password"
我拥有Hostinger商务高级邮箱套餐,恳请各位帮忙解决该问题。
内容的提问来源于stack exchange,提问作者MAYANK KUMAR
相关产品推荐
相关产品推荐

