Created
October 5, 2017 04:27
-
-
Save Synvox/245a265b68003eab53f0031108640d42 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var nodemailer = require('nodemailer') | |
var transporter = nodemailer.createTransport("SMTP", { | |
host: "smtp.domain.com", | |
secureConnection: false, | |
port: 587, | |
auth: { | |
user: "[email protected]", | |
pass: 'password' | |
}, | |
tls: { | |
ciphers:'SSLv3' | |
} | |
}) | |
const json = { | |
'[email protected]': '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 protected]>', | |
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