blob: e9c91b77275ea7cd866d2402985b455fbf3d0bf0 (
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) => {if (err) {logger.Error(err)} else {logger.Info('Sent Email')}})
}
#TLS(x) {if (x === 'true') {return true} else {return false}}
}
module.exports = () => {return new SendEmail()}
|