Guest User

Untitled

a guest
May 8th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. var nodemailer = require("nodemailer"),
  2. q = require("q"),
  3. config = require("../config.js"),
  4. transporter = nodemailer.createTransport({
  5. host: config.host,
  6. port: 587,
  7. secure: config.secure, // true for 465, false for other ports
  8. auth: {
  9. user: config.user, // generated ethereal user
  10. pass: config.password // generated ethereal password
  11. }
  12. });
  13.  
  14. /**
  15. * @description get data and mail details and send from mail to target mail
  16. * @param {string} from mail address
  17. * @param {string} to mail address
  18. * @param {string} subject mail subject
  19. * @param {string} text title of mail
  20. * @param {string} html html code as string or other content should be sent
  21. */
  22. function send(from, to, subject, text, html) {
  23. var deferred = q.defer(),
  24. message = {
  25. from: from || config.user, // sender address
  26. to: to, // list of receivers
  27. subject: subject, // Subject line
  28. text: text || 'Team', // plain text body
  29. html: html // html body
  30. };
  31. transporter.sendMail(message, function (error, info) {
  32. if (error) {
  33. deferred.reject({
  34. error: error
  35. });
  36. } else {
  37. deferred.resolve({
  38. success: info
  39. });
  40. }
  41. });
  42. return deferred.promise;
  43. }
  44.  
  45. export
  46.  
  47. s.send = send;
Add Comment
Please, Sign In to add comment