blob: 0cee2f1dfc8be17eb1df5673183fbbf1b69579a6 (
plain)
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
|
const nodemailer = require('nodemailer')
const logger = require('./logger')()
require('dotenv').config()
// Authenticates with email server and send email
class SendEmail {
constructor() {
this.transporter = nodemailer.createTransport({
host: process.env.SMTP_HOST,
port: process.env.SMTP_PORT,
secure: this.#TLS(process.env.SMTP_TLS),
auth: {
user: process.env.EMAIL_USERNAME,
pass: process.env.EMAIL_PASSWORD
},
tls: {
rejectUnauthorized: false
}
})
this.transporter.verify((err, success) => {if (err) {logger.Error(`SMTP Error: ${err.message}`)} else {logger.Info('Logged in successfully')}})
}
Send(x) {
const options = {
from: x.from,
to: process.env.EMAIL,
subject: x.subject,
html: x.message
}
this.transporter.sendMail(options, (err, info) => {err ? logger.Error(`SMTP Error: ${err.message}`) : logger.Info('SUCCESS: Email Sent')})
}
#TLS(x) {if (x === 'true') {return true} else {return false}}
}
module.exports = () => {return new SendEmail()}
|