forked from ert78gb/smtp-tester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (35 loc) · 975 Bytes
/
index.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
41
42
import nodemailer from 'nodemailer'
import { config } from 'dotenv'
config()
const transportConfig = {
host: process.env.SMTP_HOST,
port: Number.parseInt(process.env.SMTP_PORT, 10),
secure: process.env.SMTP_SECURE === 'true',
}
if (process.env.SMTP_USER)
transportConfig.auth = {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASSWORD,
}
const transporter = nodemailer.createTransport(transportConfig)
const message = {
from: process.env.EMAIL_FROM,
to: process.env.EMAIL_TO,
subject: process.env.EMAIL_SUBJECT,
text: process.env.EMAIL_TEXT,
}
if (process.env.DKIM_DOMAIN)
message.dkim = {
domainName: process.env.DKIM_DOMAIN,
keySelector: process.env.DKIM_KEY_SELECTOR,
privateKey: process.env.DKIM_PRIVATE_KEY.split('\\n').join('\n'),
}
transporter.sendMail(message)
.then(response => {
console.log(response)
process.exit()
})
.catch(error => {
console.error(error.message)
process.exit(1)
})