diff --git a/src/lib/services/email-service.test.ts b/src/lib/services/email-service.test.ts
index bc80bf148d48..af53768cd4c5 100644
--- a/src/lib/services/email-service.test.ts
+++ b/src/lib/services/email-service.test.ts
@@ -143,3 +143,29 @@ test('Can send order environments email', async () => {
expect(content.html.includes(customerId)).toBe(true);
expect(content.bcc).toBe('bcc@bcc.com');
});
+
+test('Can send productivity report email', async () => {
+ const emailService = new EmailService({
+ email: {
+ host: 'test',
+ port: 587,
+ secure: false,
+ smtpuser: '',
+ smtppass: '',
+ sender: 'noreply@getunleash.ai',
+ },
+ getLogger: noLoggerProvider,
+ } as unknown as IUnleashConfig);
+
+ const customerId = 'customer133';
+
+ const content = await emailService.sendProductivityReportEmail(
+ 'user@user.com',
+ customerId,
+ );
+ expect(content.from).toBe('noreply@getunleash.ai');
+ expect(content.subject).toBe('Unleash - productivity report');
+ expect(
+ content.html.includes(`Productivity report for customer133`),
+ ).toBe(true);
+});
diff --git a/src/lib/services/email-service.ts b/src/lib/services/email-service.ts
index 94e60a0c9f5c..54c1e917cdd6 100644
--- a/src/lib/services/email-service.ts
+++ b/src/lib/services/email-service.ts
@@ -34,6 +34,7 @@ const RESET_MAIL_SUBJECT = 'Unleash - Reset your password';
const GETTING_STARTED_SUBJECT = 'Welcome to Unleash';
const ORDER_ENVIRONMENTS_SUBJECT =
'Unleash - ordered environments successfully';
+const PRODUCTIVITY_REPORT = 'Unleash - productivity report';
const SCHEDULED_CHANGE_CONFLICT_SUBJECT =
'Unleash - Scheduled changes can no longer be applied';
const SCHEDULED_EXECUTION_FAILED_SUBJECT =
@@ -520,6 +521,64 @@ export class EmailService {
});
}
+ async sendProductivityReportEmail(
+ userEmail: string,
+ customerId: string,
+ ): Promise {
+ if (this.configured()) {
+ const context = {
+ userEmail,
+ customerId,
+ };
+
+ const bodyHtml = await this.compileTemplate(
+ 'productivity-report',
+ TemplateFormat.HTML,
+ context,
+ );
+ const bodyText = await this.compileTemplate(
+ 'productivity-report',
+ TemplateFormat.PLAIN,
+ context,
+ );
+ const email = {
+ from: this.sender,
+ to: userEmail,
+ bcc: '',
+ subject: PRODUCTIVITY_REPORT,
+ html: bodyHtml,
+ text: bodyText,
+ };
+ process.nextTick(() => {
+ this.mailer!.sendMail(email).then(
+ () =>
+ this.logger.info(
+ 'Successfully sent productivity report email',
+ ),
+ (e) =>
+ this.logger.warn(
+ 'Failed to send productivity report 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',
+ );
+ res({
+ from: this.sender,
+ to: userEmail,
+ bcc: '',
+ subject: PRODUCTIVITY_REPORT,
+ html: '',
+ text: '',
+ });
+ });
+ }
+
isEnabled(): boolean {
return this.mailer !== undefined;
}
diff --git a/src/lib/types/experimental.ts b/src/lib/types/experimental.ts
index defd86a4a630..b7441a4d979c 100644
--- a/src/lib/types/experimental.ts
+++ b/src/lib/types/experimental.ts
@@ -63,7 +63,8 @@ export type IFlagKey =
| 'webhookDomainLogging'
| 'addonUsageMetrics'
| 'releasePlans'
- | 'navigationSidebar';
+ | 'navigationSidebar'
+ | 'productivityReportEmail';
export type IFlags = Partial<{ [key in IFlagKey]: boolean | Variant }>;
@@ -316,6 +317,10 @@ const flags: IFlags = {
process.env.UNLEASH_EXPERIMENTAL_SIDEBAR_NAVIGATION,
true,
),
+ productivityReportEmail: parseEnvVarBoolean(
+ process.env.UNLEASH_EXPERIMENTAL_PRODUCTIVITY_REPORT_EMAIL,
+ false,
+ ),
};
export const defaultExperimentalOptions: IExperimentalOptions = {
diff --git a/src/mailtemplates/productivity-report/productivity-report.html.mustache b/src/mailtemplates/productivity-report/productivity-report.html.mustache
new file mode 100644
index 000000000000..d8c23d4dd1f7
--- /dev/null
+++ b/src/mailtemplates/productivity-report/productivity-report.html.mustache
@@ -0,0 +1,320 @@
+
+
+
+
+ *|MC:SUBJECT|*
+
+
+
+ Productivity report for {{customerId}}
+
+
diff --git a/src/mailtemplates/productivity-report/productivity-report.plain.mustache b/src/mailtemplates/productivity-report/productivity-report.plain.mustache
new file mode 100644
index 000000000000..6d9094ab55d8
--- /dev/null
+++ b/src/mailtemplates/productivity-report/productivity-report.plain.mustache
@@ -0,0 +1,5 @@
+Subject: Unleash productivity report
+
+Hello,
+
+Productivity report