diff options
author | Sam Wilkins <samwilkins333@gmail.com> | 2020-01-10 06:00:50 -0500 |
---|---|---|
committer | Sam Wilkins <samwilkins333@gmail.com> | 2020-01-10 06:00:50 -0500 |
commit | cf3e869023d3027ae42c828ba3670b77d838ac50 (patch) | |
tree | 9e02cf0fc5ed1d8c341530fa98dc05adfc476c7e /src/server/ActionUtilities.ts | |
parent | a8aa0facfaa23298398c15aa906bc6d69c538564 (diff) |
email takes in object, commented debug zip, promisified inter-process messaging, streamlined session manager route responses
Diffstat (limited to 'src/server/ActionUtilities.ts')
-rw-r--r-- | src/server/ActionUtilities.ts | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/server/ActionUtilities.ts b/src/server/ActionUtilities.ts index f0bfbc525..60f66c878 100644 --- a/src/server/ActionUtilities.ts +++ b/src/server/ActionUtilities.ts @@ -119,16 +119,24 @@ export namespace Email { } }); + export interface DispatchOptions<T extends string | string[]> { + to: T; + subject: string; + content: string; + attachments?: Mail.Attachment | Mail.Attachment[]; + } + export interface DispatchFailure { recipient: string; error: Error; } - export async function dispatchAll(recipients: string[], subject: string, content: string) { + export async function dispatchAll({ to, subject, content, attachments }: DispatchOptions<string[]>) { const failures: DispatchFailure[] = []; - await Promise.all(recipients.map(async (recipient: string) => { + await Promise.all(to.map(async recipient => { let error: Error | null; - if ((error = await Email.dispatch(recipient, subject, content)) !== null) { + const resolved = attachments ? "length" in attachments ? attachments : [attachments] : undefined; + if ((error = await Email.dispatch({ to: recipient, subject, content, attachments: resolved })) !== null) { failures.push({ recipient, error @@ -138,17 +146,15 @@ export namespace Email { return failures.length ? failures : undefined; } - export async function dispatch(recipient: string, subject: string, content: string, attachments?: Mail.Attachment[]): Promise<Error | null> { + export async function dispatch({ to, subject, content, attachments }: DispatchOptions<string>): Promise<Error | null> { const mailOptions = { - to: recipient, + to, from: 'brownptcdash@gmail.com', subject, - text: `Hello ${recipient.split("@")[0]},\n\n${content}`, + text: `Hello ${to.split("@")[0]},\n\n${content}`, attachments } as MailOptions; - return new Promise<Error | null>(resolve => { - smtpTransport.sendMail(mailOptions, resolve); - }); + return new Promise<Error | null>(resolve => smtpTransport.sendMail(mailOptions, resolve)); } }
\ No newline at end of file |