aboutsummaryrefslogtreecommitdiff
path: root/src/server/ActionUtilities.ts
diff options
context:
space:
mode:
authorFawn <fangrui_tong@brown.edu>2020-01-09 15:52:05 -0500
committerFawn <fangrui_tong@brown.edu>2020-01-09 15:52:05 -0500
commit9a8d2a903b10568686cc66c849fba21b1ab75be2 (patch)
treeea0bf48e4f47c72f9eeab3cbd00a5f1494abbb34 /src/server/ActionUtilities.ts
parente0a8d325d601d305a166c1683dccfcc67e91fe95 (diff)
parent540bda7295f6ee7c2eed848598de6f5df74b2723 (diff)
pull and merge with master
Diffstat (limited to 'src/server/ActionUtilities.ts')
-rw-r--r--src/server/ActionUtilities.ts23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/server/ActionUtilities.ts b/src/server/ActionUtilities.ts
index 30aed32e6..a93566fb1 100644
--- a/src/server/ActionUtilities.ts
+++ b/src/server/ActionUtilities.ts
@@ -118,25 +118,34 @@ export namespace Email {
}
});
+ export interface DispatchFailure {
+ recipient: string;
+ error: Error;
+ }
+
export async function dispatchAll(recipients: string[], subject: string, content: string) {
- const failures: string[] = [];
+ const failures: DispatchFailure[] = [];
await Promise.all(recipients.map(async (recipient: string) => {
- if (!await Email.dispatch(recipient, subject, content)) {
- failures.push(recipient);
+ let error: Error | null;
+ if ((error = await Email.dispatch(recipient, subject, content)) !== null) {
+ failures.push({
+ recipient,
+ error
+ });
}
}));
- return failures;
+ return failures.length ? failures : undefined;
}
- export async function dispatch(recipient: string, subject: string, content: string): Promise<boolean> {
+ export async function dispatch(recipient: string, subject: string, content: string): Promise<Error | null> {
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));
+ return new Promise<Error | null>(resolve => {
+ smtpTransport.sendMail(mailOptions, resolve);
});
}