Skip to content

Instantly share code, notes, and snippets.

@Synvox
Created October 5, 2017 04:27
Show Gist options
  • Save Synvox/245a265b68003eab53f0031108640d42 to your computer and use it in GitHub Desktop.
Save Synvox/245a265b68003eab53f0031108640d42 to your computer and use it in GitHub Desktop.
var nodemailer = require('nodemailer')
var transporter = nodemailer.createTransport("SMTP", {
host: "smtp.domain.com",
secureConnection: false,
port: 587,
auth: {
user: "email@domain.com",
pass: 'password'
},
tls: {
ciphers:'SSLv3'
}
})
const json = {
'email@domain.com': 'John Doe'
}
const arr = Object.keys(json).map((key)=>{
return {email: key, name: json[key]}
})
let total = arr.length
const send = ()=>{
if (!arr[index]) {
console.log('Finished')
return
}
const {name, email} = arr[index]
var mailOptions = {
from: 'John Doe <email@domain.com>',
to: `${name} <${email}>`,
subject: 'This is my subject',
text:
`
To ${name}
This is an email
John Doe.
`
}
transporter.sendMail(mailOptions, function(error, info){
if(error){
console.log(error)
} else {
console.log(`Message sent: ${name} <${email}> ${(index+1)} of ${total} (${(index/total * 100).toFixed(1)})%`)
}
index++
setTimeout(()=>{
send()
},3000)
})
}
send()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment