Guest User

Untitled

a guest
Dec 4th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. 'use strict';
  2. const nodemailer = require('nodemailer');
  3. const fs = require('fs');
  4. // Generate test SMTP service account from ethereal.email
  5. // Only needed if you don't have a real mail account for testing
  6. nodemailer.createTestAccount((err, account) => {
  7.  
  8. // create reusable transporter object using the default SMTP transport
  9. let transporter = nodemailer.createTransport({
  10. host: 'smtp.gmail.com',
  11. port: 587,
  12. // secureConnection: false,
  13. secure: false, // true for 465, false for other ports
  14. auth: {
  15. user: "abdulw976@gmail.com", // generated ethereal user
  16. pass: "abdulwahab" // generated ethereal password
  17. },
  18. tls: {
  19. ciphers:'SSLv3',
  20. rejectUnauthorized: false
  21. },
  22. });
  23.  
  24. // setup email data with unicode symbols
  25. let mailOptions = {
  26. from: 'dfdh@globallogic.com', // sender address
  27. to: 'abdulwajid.nasar@globallogic.com', // list of receivers
  28. subject: 'Hello ✔', // Subject line
  29. text: 'Hello world?', // plain text body
  30. // html: '<b>Hello world?</b>' // html body
  31. html: 'Embedded image1: <img src="/home/moda/Pictures/errors.png"/>',
  32. attachments: [
  33. { // utf-8 string as an attachment
  34. filename: 'text1.txt',
  35. content: 'first text'
  36. },
  37. { // binary buffer as an attachment
  38. filename: 'text2.txt',
  39. content: new Buffer('second text','utf-8')
  40. },
  41. { // stream as an attachment
  42. filename: 'errors.png',
  43. content: fs.createReadStream('/home/moda/Pictures/errors.png')
  44. }]
  45. };
  46.  
  47.  
  48. // send mail with defined transport object
  49. transporter.sendMail(mailOptions, (error, info) => {
  50. if (error) {
  51. return console.log(error);
  52. }
  53. console.log('Message sent: %s', info.messageId);
  54. // Preview only available when sending through an Ethereal account
  55. console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
  56.  
  57. // Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@blurdybloop.com>
  58. // Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
  59. });
  60. });
Add Comment
Please, Sign In to add comment