(bug)(subscription) promisify mailer – otherwise when sending subscriptions, emails are marked as sent even if there's been an error

in this case: "454 Throttling failure: Maximum sending rate exceeded."
This commit is contained in:
Andrea Vos 2025-02-02 15:57:38 +01:00
parent 19b3bf45ea
commit 79b5bf1c2d

View File

@ -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<void> => {
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<void> => {
if (typeof template === 'string') {
template = templates[template];
}
sendEmail(
await sendEmail(
process.env.MAILER_OVERWRITE || to,
applyTemplate(template, 'subject', params),
applyTemplate(template, 'text', params),