Skip to content

Instantly share code, notes, and snippets.

@ziyoung
Created June 6, 2019 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ziyoung/b885928bfb4663c09ab4fc15f31858d6 to your computer and use it in GitHub Desktop.
Save ziyoung/b885928bfb4663c09ab4fc15f31858d6 to your computer and use it in GitHub Desktop.
批量发送邮件
const nodemailer = require('nodemailer');
const config = require('./config.json');
const wait = () => new Promise(resolve => setTimeout(resolve, 800));
async function main() {
let transporter = nodemailer.createTransport({
host: "email.example.com",
port: 587,
secure: false, // true for 465, false for other ports
auth: {
user: "",
pass: ""
}
});
for (const email of Object.keys(config)) {
try {
if (text) {
let info = await transporter.sendMail({
from: '"Name" <user@example.com>', // sender address
to: email, // list of receivers
subject: 'title', // Subject line
html: '<p>test</p>' // html body
});
console.log('Message sent: %s', info.messageId);
console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
}
} catch (error) {
console.error(error);
}
await wait();
}
}
main().catch(console.error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment