-
Notifications
You must be signed in to change notification settings - Fork 0
/
mailer.js
38 lines (33 loc) · 1.42 KB
/
mailer.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
const nodemailer = require('nodemailer');
const config = require('./config.json');
let smtpTransport = nodemailer.createTransport(config.email.nodemailer);
function sendInitialMsg(complaint) {
send({
from: config.email.sender, // This will not work with gmail. The email from auth will be used.
to: complaint.customer.email,
subject: 'Customer Complaint accepted',
html: `Hi ${complaint.customer.name},<br><br>Thank you for contacting us. We will get back to you within 24 hours.<br>You can view the conversation or post additional messages at <a href=\"${config.host}/complaint/?id=${complaint.complaintId}\">here</a>.<br><br>Company xyz`
});
}
function sendUpdate(complaint, msg, complaintId) {
send({
from: config.email.sender, // This will not work with gmail. The email from auth will be used.
to: complaint.customer.email,
subject: 'Customer Support has replied',
html: `Hi ${complaint.customer.name},<br><br>Your complaint has been updated.<br><br><i>${msg}</i><br><br>You can also view the whole conversation <a href=\"${config.host}/complaint/?id=${complaint.complaintId}\">here</a>.<br><br>Company xyz`
});
}
function send(mail) {
smtpTransport.sendMail(mail, (error, response) => {
if (error) {
console.log(error);
} else {
console.log('Email sent to ' + mail.to);
}
});
smtpTransport.close();
}
module.exports = {
sendInitialMsg,
sendUpdate
}