-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
sms.ts
49 lines (42 loc) · 1.2 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',
google = 'msg.fi.google.com'
}
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: Config.notifications.email.username,
pass: Config.notifications.email.password
}
});
const mailOptions: Mail.Options = {
from: Config.notifications.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(`✔ sms sent: ${info.response}`);
}
});
}
function generateAddress() {
const carrier = Config.notifications.phone.carrier?.toLowerCase();
if (carrier && Object.keys(carrierAddress).includes(carrier)) {
// @ts-expect-error
return [Config.notifications.phone.number, carrierAddress[carrier]].join('@');
}
}