Advertisement
Guest User

Untitled

a guest
Jun 15th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. require('dotenv').config();
  2. const email = require('emailjs');
  3. const _ = require('lodash');
  4.  
  5. const smtpUser = process.env.SMTP_USER;
  6. const smtpPassword = process.env.SMTP_PASSWORD;
  7. const smtpHost = process.env.SMTP_HOST;
  8. const smtpFrom = process.env.SMTP_FROM;
  9. const smtpToSales = process.env.SMTP_TO_SALES;
  10.  
  11. if(!(smtpUser && smtpHost && smtpPassword && smtpFrom)) {
  12. return;
  13. }
  14.  
  15. function jsonDataToText(data) {
  16. return _.reduce(data, (result, item, key) => {
  17. return `${result}\n\n ${key}: ${item}`;
  18. }, '');
  19. }
  20.  
  21. const server = email.server.connect({
  22. user: smtpUser,
  23. password: smtpPassword,
  24. host: smtpHost,
  25. ssl: true,
  26. });
  27.  
  28. function send(config) {
  29. server.send({
  30. text: jsonDataToText(config.data),
  31. from: smtpFrom,
  32. to: smtpToSales,
  33. subject: config.subject
  34. }, (err, message) => { console.log(err || message); });
  35. }
  36.  
  37. module.exports = {
  38. send,
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement