Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new email template for scheduled-execution-failed email #5519

Merged
merged 7 commits into from
Dec 1, 2023
70 changes: 70 additions & 0 deletions src/lib/services/email-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export interface IEmailEnvelope {

const RESET_MAIL_SUBJECT = 'Unleash - Reset your password';
const GETTING_STARTED_SUBJECT = 'Welcome to Unleash';
const SCHEDULED_EXECUTION_FAILED_SUBJECT =
'Unleash - Scheduled execution failed';
andreas-unleash marked this conversation as resolved.
Show resolved Hide resolved

export const MAIL_ACCEPTED = '250 Accepted';

Expand Down Expand Up @@ -68,6 +70,74 @@ export class EmailService {
}
}

async sendScheduledExecutionFailedEmail(
name: string,
recipient: string,
changeRequestLink: string,
scheduledAt: string,
errorMessage: string,
): Promise<IEmailEnvelope> {
if (this.configured()) {
const year = new Date().getFullYear();
const bodyHtml = await this.compileTemplate(
'scheduled-execution-failed',
TemplateFormat.HTML,
{
changeRequestLink,
scheduledAt,
errorMessage,
name,
year,
},
);
const bodyText = await this.compileTemplate(
'scheduled-execution-failed',
TemplateFormat.PLAIN,
{
changeRequestLink,
scheduledAt,
errorMessage,
name,
year,
},
);
const email = {
from: this.sender,
to: recipient,
subject: SCHEDULED_EXECUTION_FAILED_SUBJECT,
html: bodyHtml,
text: bodyText,
};
process.nextTick(() => {
this.mailer!.sendMail(email).then(
() =>
this.logger.info(
'Successfully sent scheduled-execution-failed email',
),
(e) =>
this.logger.warn(
'Failed to send scheduled-execution-failed email',
e,
),
);
});
return Promise.resolve(email);
}
return new Promise((res) => {
this.logger.warn(
'No mailer is configured. Please read the docs on how to configure an email service',
);
this.logger.debug('Change request link: ', changeRequestLink);
res({
from: this.sender,
to: recipient,
subject: SCHEDULED_EXECUTION_FAILED_SUBJECT,
html: '',
text: '',
});
});
}

async sendResetMail(
name: string,
recipient: string,
Expand Down
Loading
Loading