Advertisement
Guest User

Untitled

a guest
Oct 5th, 2017
445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. var nodemailer = require('nodemailer')
  2.  
  3. var transporter = nodemailer.createTransport("SMTP", {
  4. host: "smtp.domain.com",
  5. secureConnection: false,
  6. port: 587,
  7. auth: {
  8. user: "email@domain.com",
  9. pass: 'password'
  10. },
  11. tls: {
  12. ciphers:'SSLv3'
  13. }
  14. })
  15.  
  16. const json = {
  17. 'email@domain.com': 'John Doe'
  18. }
  19. const arr = Object.keys(json).map((key)=>{
  20. return {email: key, name: json[key]}
  21. })
  22.  
  23. let total = arr.length
  24. const send = ()=>{
  25. if (!arr[index]) {
  26. console.log('Finished')
  27. return
  28. }
  29.  
  30. const {name, email} = arr[index]
  31.  
  32. var mailOptions = {
  33. from: 'John Doe <email@domain.com>',
  34. to: `${name} <${email}>`,
  35. subject: 'This is my subject',
  36. text:
  37. `
  38. To ${name}
  39.  
  40. This is an email
  41.  
  42. John Doe.
  43. `
  44. }
  45.  
  46. transporter.sendMail(mailOptions, function(error, info){
  47. if(error){
  48. console.log(error)
  49. } else {
  50. console.log(`Message sent: ${name} <${email}> ${(index+1)} of ${total} (${(index/total * 100).toFixed(1)})%`)
  51. }
  52. index++
  53. setTimeout(()=>{
  54. send()
  55. },3000)
  56. })
  57.  
  58. }
  59.  
  60. send()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement