aboutsummaryrefslogtreecommitdiff
path: root/src/server/session_manager/email.ts
blob: a638644db7fbe7f370ba0246532890017595f15c (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
import * as nodemailer from "nodemailer";
import { MailOptions } from "nodemailer/lib/json-transport";

export namespace Email {

    const smtpTransport = nodemailer.createTransport({
        service: 'Gmail',
        auth: {
            user: 'brownptcdash@gmail.com',
            pass: 'browngfx1'
        }
    });

    export async function dispatch(recipient: string, subject: string, content: string): Promise<boolean> {
        const mailOptions = {
            to: recipient,
            from: 'brownptcdash@gmail.com',
            subject,
            text: `Hello ${recipient.split("@")[0]},\n\n${content}`
        } as MailOptions;
        return new Promise<boolean>(resolve => {
            smtpTransport.sendMail(mailOptions, (dispatchError: Error | null) => resolve(dispatchError === null));
        });
    }

}