Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
local-repairs-tracking-system/Mail/mailer.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
83 lines (75 sloc)
2 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
'use strict' | |
const nodemailer = require('nodemailer') | |
// MAILTRAP INFO | |
const mailUser = 'd0c80fa6e29572' | |
const mailPass = '49aef1f003a410' | |
const mailHost = 'smtp.mailtrap.io' | |
const mailPort = 2525 | |
module.exports = class Mailer { | |
async message(user, tech, quote) { | |
return `<h3>Hi ${user.user}</h3> | |
<br> | |
<p>We are glad to work with you and glad to advise you that ${tech.user} has been assigned | |
to one of our technician!</p> | |
<br> | |
<p>Upon completion of job '${quote.jobId}', which will occur on${quote.executionDate} | |
at ${quote.executionTime}, | |
you should pay £ ${quote.price}.</p> | |
<br> | |
<p>Expectated a 100% work from us!</p> | |
<br> | |
<p>Regards,</p> | |
<br> | |
<p>365Domestic Repair Team</p>` | |
} | |
async finishedMsg(jobId, tech,user) { | |
return `<h3>Hi ${user.user}</h3> | |
<br> | |
<p>We are excited to inform you that job '${jobId}' was successfully excuted. it is fixed now!</p> | |
<br> | |
<p>we Hope you're glad!</p> | |
<br> | |
<p>Regards from 365repairs.com and ${tech.user}</p>` | |
} | |
async mail(user, tech, quote) { | |
const transporter = nodemailer.createTransport({ | |
host: mailHost, | |
port: mailPort, | |
auth: { | |
user: mailUser, | |
pass: mailPass | |
} | |
}) | |
const mailOptions = { | |
from: `${tech.email}`, | |
to: `${user.email}`, | |
subject: `Quote for job ${quote.jobId}`, | |
html: await this.message(user, tech, quote) | |
} | |
transporter.sendMail(mailOptions, (error, info) => { | |
if (error) console.log(error) | |
else console.log(`Email sent: ${info.response}`) | |
}) | |
} | |
async finishMail(jobId, tech,user) { | |
const transporter = nodemailer.createTransport({ | |
host: mailHost, | |
port: mailPort, | |
auth: { | |
user: mailUser, | |
pass: mailPass | |
} | |
}) | |
const mailOptions = { | |
from: `${tech.email}`, | |
to: `${user.email}`, | |
subject: `Job ${jobId} Finished`, | |
html: await this.finishedMsg(jobId, tech,user) | |
} | |
transporter.sendMail(mailOptions, (error, info) => { | |
if (error) console.log(error) | |
else console.log(`Email sent: ${info.response}`) | |
}) | |
} | |
} |