diff --git a/server/mailer.ts b/server/mailer.ts index 2e150bb87..e3879023b 100644 --- a/server/mailer.ts +++ b/server/mailer.ts @@ -23,30 +23,32 @@ if (!transport && process.env.NODE_ENV === 'development') { } const transporter = nodemailer.createTransport(transport); -const sendEmail = ( +const sendEmail = async ( to: string, subject: string, text: string | undefined = undefined, html: string | undefined = undefined, from: string | undefined = undefined, -): void => { - transporter.sendMail({ - to, - subject, - text, - html, - from: from || process.env.MAILER_FROM, - }, function (err, info) { +): Promise => { + try { + const info = await transporter.sendMail({ + to, + subject, + text, + html, + from: from || process.env.MAILER_FROM, + }); + if (process.env.NODE_ENV === 'development') { const streamInfo = info as StreamTransport.SentMessageInfo; if (streamInfo.message) { (streamInfo.message as Readable).pipe(process.stdout); } } - if (err) { - Sentry.captureException(err); - } - }); + } catch (err) { + Sentry.captureException(err); + throw err; + } }; const findTranslation = (key: string) => { @@ -244,12 +246,12 @@ const applyTemplate = ( return templateText; }; -export default (to: string, template: string | Template, params = {}): void => { +export default async (to: string, template: string | Template, params = {}): Promise => { if (typeof template === 'string') { template = templates[template]; } - sendEmail( + await sendEmail( process.env.MAILER_OVERWRITE || to, applyTemplate(template, 'subject', params), applyTemplate(template, 'text', params),