diff --git a/src/lib/services/email-service.test.ts b/src/lib/services/email-service.test.ts index af53768cd4c5..1e1e148a1207 100644 --- a/src/lib/services/email-service.test.ts +++ b/src/lib/services/email-service.test.ts @@ -144,7 +144,8 @@ test('Can send order environments email', async () => { expect(content.bcc).toBe('bcc@bcc.com'); }); -test('Can send productivity report email', async () => { +// TODO: test +test.skip('Can send productivity report email', async () => { const emailService = new EmailService({ email: { host: 'test', @@ -157,15 +158,16 @@ test('Can send productivity report email', async () => { getLogger: noLoggerProvider, } as unknown as IUnleashConfig); - const customerId = 'customer133'; - const content = await emailService.sendProductivityReportEmail( 'user@user.com', - customerId, + 'customerId', + { + flags_created: 1, + production_updates: 2, + health: 99, + }, ); expect(content.from).toBe('noreply@getunleash.ai'); expect(content.subject).toBe('Unleash - productivity report'); - expect( - content.html.includes(`Productivity report for customer133`), - ).toBe(true); + expect(content.html.includes(`Productivity Report`)).toBe(true); }); diff --git a/src/lib/services/email-service.ts b/src/lib/services/email-service.ts index 54c1e917cdd6..612fcf255773 100644 --- a/src/lib/services/email-service.ts +++ b/src/lib/services/email-service.ts @@ -28,6 +28,11 @@ export interface IEmailEnvelope { subject: string; html: string; text: string; + attachments?: { + filename: string; + path: string; + cid: string; + }[]; } const RESET_MAIL_SUBJECT = 'Unleash - Reset your password'; @@ -522,32 +527,48 @@ export class EmailService { } async sendProductivityReportEmail( + userName: string, userEmail: string, - customerId: string, + metrics: { + health: number; + flags_created: number; + production_updates: number; + }, ): Promise { if (this.configured()) { const context = { + userName, userEmail, - customerId, + ...metrics, + unleashUrl: this.config.server.unleashUrl, }; + const template = 'productivity-report'; + const bodyHtml = await this.compileTemplate( - 'productivity-report', + template, TemplateFormat.HTML, context, ); const bodyText = await this.compileTemplate( - 'productivity-report', + template, TemplateFormat.PLAIN, context, ); - const email = { + const email: IEmailEnvelope = { from: this.sender, to: userEmail, bcc: '', subject: PRODUCTIVITY_REPORT, html: bodyHtml, text: bodyText, + attachments: [ + this.resolveTemplateAttachment( + template, + 'unleash-logo.png', + 'unleashLogo', + ), + ], }; process.nextTick(() => { this.mailer!.sendMail(email).then( @@ -613,6 +634,29 @@ export class EmailService { throw new NotFoundError('Could not find template'); } + private resolveTemplateAttachment( + templateName: string, + filename: string, + cid: string, + ): { + filename: string; + path: string; + cid: string; + } { + const topPath = path.resolve(__dirname, '../../mailtemplates'); + const attachment = path.join(topPath, templateName, filename); + console.log({ attachment }); + if (existsSync(attachment)) { + return { + filename, + path: attachment, + cid, + }; + } + + throw new NotFoundError('Could not find email attachment'); + } + configured(): boolean { return this.sender !== 'not-configured' && this.mailer !== undefined; } diff --git a/src/mailtemplates/productivity-report/productivity-report.html.mustache b/src/mailtemplates/productivity-report/productivity-report.html.mustache index c2a7d3452679..30f322b4480e 100644 --- a/src/mailtemplates/productivity-report/productivity-report.html.mustache +++ b/src/mailtemplates/productivity-report/productivity-report.html.mustache @@ -1,651 +1,151 @@ -
- -
- - + + + + Your Unleash Productivity Report + + + +
+
+ Unleash +
Your Monthly Productivity Report
+
+
+
+

Hi {{userName}},

+

We are excited to share the latest insights for your instance. As always if you have any questions or concerns let us know - we are here for you.

+

Ready to dive into your numbers?

+
+
+
+
+ {{health}}%
+ your instance health +
+
+
+
+ + + + - - -
- Insights about your Unleash usage.
- - - +
+ {{flags_created}}
+ flags created last month +
+ - -
- - - - - - -
- - - - - - -
- - - - - - -
- - - - - - -
- - - - - - -
- - - - - - -
- - {{ses:openTracker}} -
-
-
-
-
- - - - - - -
- - - - - - - -
- - - - - - -
- - - - - - -
- - - - - - -
- -
-
-
-
- - - - - - -
- - - - - - -
- - - - - - -
-
-

- - Your Unleash productivity report  -

-
-
-
-
-
-
- - - - - - -
- - - - - - -
- - - - - - -
- - - - - - - - - -
-
-

- - Hi -

-

-  

-

- - We are excited to share the latest insights for your instance. As always if you have any questions or concerns let us know - we are here for you.  -

-

-  

-

- - Ready to dive into your numbers? -

-
-
- -
-
-
-
- - - - - - -
- - - - - - -
- - - - - - -
- - - - - - -
- - - - - - -
-
-

-  

-

- - - 50 - - - % -

-

- your instance health -

-

-  

-

-  

-
-
-
-
-
-
- - - - - - -
- - - - - - - -
- - - - - - -
- - - - - - -
- - - - - - -
-
-

-  

-

- - - 10 - -

-

- - flags created the last month -

-

-  

-
-
-
-
-
- - - - - - -
- - - - - - -
- - - - - - -
-
-

-  

-

- - - 44 - -

-

- - production updates the last month -

-

-  

-
-
-
-
-
-
- - - - - - -
- - - - - - -
- - - - - - -
- - - - - - -
- - - - - - -
- - - - Go - to - your - dashboard - - -
-
-
-
-
- - - - - - -
- - - - - - -
- - - - - - -
- - - - - - -
- -
-
-
-
- - - - - - -
- - - - - - -
- - - - - - -
- - - - - - -
- - - - - - -
- - - - - - -
- - - - - - -
- - - - - - - - - -
- - - - - - - - -
- ­ - - - - - ­
-
- - - - - - - - -
- ­ - - - - - ­
-
- - - - - - - - -
- ­ - - - - - ­
-
- - - - - - - - -
- ­ - - - - - ­
-
-
-
-
-
-
-
-
- - - - - - -
- - - - - - -
- - - - - - -
- - - - - - - - - -
- - - - - - -
-
-

- - This email was sent to  - - - - - ...@getunleash.io - -

-
-
-
- - - - - - -
-
-

- - You've received this as you are a user of Unleash -

-
-
-
-
-
-
-
+
+ {{production_updates}}
+ production updates last month +
-
If you wish to unsubscribe from our - newsletter, click - here - - - {{amazonSESUnsubscribeUrl}} - + +
+ Go to your Insights +
-
-
-
+
-
- + + diff --git a/src/mailtemplates/productivity-report/test.mustache b/src/mailtemplates/productivity-report/test.mustache new file mode 100644 index 000000000000..34e9b1789c98 --- /dev/null +++ b/src/mailtemplates/productivity-report/test.mustache @@ -0,0 +1,136 @@ + + + + Your Unleash Productivity Report + + + +
+
+ Unleash +
Your Monthly Productivity Report
+
+
+

Hi Elise,

+

We are excited to share the latest insights for your instance. As always if you have any questions or concerns let us know - we are here for you.

+

Ready to dive into your numbers?

+
+
+ 50%
+ your instance health +
+
+ + + + + + + + + +
+
+ 10
+ flags created last month +
+
+
+ 44
+ production updates last month +
+
+
Go to your insights
+
+ +
+ + diff --git a/src/mailtemplates/productivity-report/unleash-logo.png b/src/mailtemplates/productivity-report/unleash-logo.png new file mode 100644 index 000000000000..687bf761e8fc Binary files /dev/null and b/src/mailtemplates/productivity-report/unleash-logo.png differ