diff --git a/src/lib/services/email-service.ts b/src/lib/services/email-service.ts index acb6d38b991f..54ce3ddad16f 100644 --- a/src/lib/services/email-service.ts +++ b/src/lib/services/email-service.ts @@ -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 change request could not be applied'; export const MAIL_ACCEPTED = '250 Accepted'; @@ -68,6 +70,76 @@ export class EmailService { } } + async sendScheduledExecutionFailedEmail( + name: string, + recipient: string, + changeRequestLink: string, + changeRequestTitle: string, + scheduledAt: string, + errorMessage: string, + ): Promise { + 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, + changeRequestTitle, + 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, diff --git a/src/mailtemplates/scheduled-execution-failed/scheduled-execution-failed.html.mustache b/src/mailtemplates/scheduled-execution-failed/scheduled-execution-failed.html.mustache new file mode 100644 index 000000000000..acab22bd2223 --- /dev/null +++ b/src/mailtemplates/scheduled-execution-failed/scheduled-execution-failed.html.mustache @@ -0,0 +1,522 @@ + + + + + *|MC:SUBJECT|* + + + +
+ + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + +
+ Scheduled change request failed to apply + + Email not displaying correctly?
View it in your browser. +
+ +
+ + + + + +
+ +
+ +
+ + + + + +
+

Scheduled change request failed to apply

+ +
+ Scheduled change request {{{ changeRequestTitle }}} failed to apply at {{{ scheduledAt }}} due to {{{ errorMessage }}}. +
+ You can reschedule the change request to try again later or reject the changes to close it. +
+
+ +
+ + + + + + + + + +
+ Follow us on Github +
+ Copyright © {{ year }} | Bricks Software | All rights reserved. +
+ +
+ Our mailing address is: team@getunleash.io +
+ +
+ +
+ +
+
+ + diff --git a/src/mailtemplates/scheduled-execution-failed/scheduled-execution-failed.plain.mustache b/src/mailtemplates/scheduled-execution-failed/scheduled-execution-failed.plain.mustache new file mode 100644 index 000000000000..857c71434583 --- /dev/null +++ b/src/mailtemplates/scheduled-execution-failed/scheduled-execution-failed.plain.mustache @@ -0,0 +1,6 @@ +Scheduled change request failed to apply + +Scheduled change request {{{ changeRequestTitle }}} ({{{ changeRequestLink }}}) failed to apply at {{{ scheduledAt }}} due to {{{ errorMessage }}}. + +You can reschedule the change request to try again later or reject the changes to close it. +