-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
sms.ts
49 lines (42 loc) · 1.13 KB
/
sms.ts
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
43
44
45
46
47
48
49
import nodemailer from 'nodemailer';
import Mail from 'nodemailer/lib/mailer';
import {Config} from '../config';
import {Logger} from '../logger';
const subject = 'NVIDIA - BUY NOW';
enum carrierAddress {
sprint = 'messaging.sprintpcs.com',
verizon = 'vtext.com',
tmobile = 'tmomail.net',
att = 'txt.att.net'
}
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: Config.email.username,
pass: Config.email.password
}
});
const mailOptions: Mail.Options = {
from: Config.email.username,
to: generateAddress(),
subject
};
export default function sendSMS(text: string) {
mailOptions.text = text;
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
Logger.error(error);
} else {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
Logger.info(`✔ email sent: ${info.response}`);
}
});
}
function generateAddress() {
for (const carrier of Object.keys(carrierAddress)) {
if (Config.phone.carrier && carrier === Config.phone.carrier.toLowerCase()) {
// @ts-expect-error
return [Config.phone.number, carrierAddress[carrier]].join('@');
}
}
}