Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require('dotenv').config();
- const email = require('emailjs');
- const _ = require('lodash');
- const smtpUser = process.env.SMTP_USER;
- const smtpPassword = process.env.SMTP_PASSWORD;
- const smtpHost = process.env.SMTP_HOST;
- const smtpFrom = process.env.SMTP_FROM;
- const smtpToSales = process.env.SMTP_TO_SALES;
- if(!(smtpUser && smtpHost && smtpPassword && smtpFrom)) {
- return;
- }
- function jsonDataToText(data) {
- return _.reduce(data, (result, item, key) => {
- return `${result}\n\n ${key}: ${item}`;
- }, '');
- }
- const server = email.server.connect({
- user: smtpUser,
- password: smtpPassword,
- host: smtpHost,
- ssl: true,
- });
- function send(config) {
- server.send({
- text: jsonDataToText(config.data),
- from: smtpFrom,
- to: smtpToSales,
- subject: config.subject
- }, (err, message) => { console.log(err || message); });
- }
- module.exports = {
- send,
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement