-
Notifications
You must be signed in to change notification settings - Fork 0
/
send.js
40 lines (35 loc) · 1.21 KB
/
send.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#! /usr/bin/env node
const inquirer = require('inquirer');
const { options } = require('./env/config');
const questions = require('./utils/questions');
const {
sendEmailWithAttachment,
sendEmailWithoutAttachment,
initTransporter,
} = require('./utils/emailUtils');
inquirer
.prompt(questions)
.then(async (answers) => {
const {
attachment,
} = answers;
try {
const transporter = await initTransporter(options);
// check if the connection config is ok and the attachement is empty
if (transporter && !attachment.length) {
const emailSent = await sendEmailWithoutAttachment(transporter, answers);
console.log('Email sent without an attachement successfully: ', emailSent);
return emailSent;
}
// check if the connection config is ok and the attachement is not empty
if (transporter && attachment.length) {
const emailSent = await sendEmailWithAttachment(transporter, answers);
console.log('Email sent with an attachement successfully: ', emailSent);
return emailSent;
}
console.error('Error with connection configuration: ', transporter);
return false;
} catch (error) {
return error;
}
});