diff options
Diffstat (limited to 'src/server/session_manager/crash_email.ts')
-rw-r--r-- | src/server/session_manager/crash_email.ts | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/server/session_manager/crash_email.ts b/src/server/session_manager/crash_email.ts new file mode 100644 index 000000000..7783cd779 --- /dev/null +++ b/src/server/session_manager/crash_email.ts @@ -0,0 +1,36 @@ +import * as nodemailer from "nodemailer"; +import { MailOptions } from "nodemailer/lib/json-transport"; + +export namespace CrashEmail { + + export async function dispatch(error: Error, recipients: string[]): Promise<boolean[]> { + const smtpTransport = nodemailer.createTransport({ + service: 'Gmail', + auth: { + user: 'brownptcdash@gmail.com', + pass: 'browngfx1' + } + }); + return Promise.all(recipients.map(recipient => new Promise<boolean>(resolve => { + const mailOptions = { + to: recipient, + from: 'brownptcdash@gmail.com', + subject: 'Dash Server Crash', + text: emailText(recipient, error) + } as MailOptions; + smtpTransport.sendMail(mailOptions, (dispatchError: Error | null) => resolve(dispatchError === null)); + }))); + } + + function emailText(recipient: string, { name, message, stack }: Error) { + return [ + `Hey ${recipient.split("@")[0]},`, + "You, as a Dash Administrator, are being notified of a server crash event. Here's what we know:", + `name:\n${name}`, + `message:\n${message}`, + `stack:\n${stack}`, + "The server is already restarting itself, but if you're concerned, use the Remote Desktop Connection to monitor progress." + ].join("\n\n"); + } + +}
\ No newline at end of file |