Skip to content

Commit dcb1c15

Browse files
committed
WIP: Send added-to-team emails
Needs testing with an actual email client to confirm styles etc. Maybe refactor to extract email templates so we can easily test them separately now and in future?
1 parent 090c1da commit dcb1c15

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

api/src/functions/update-team.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
import { getCorsResponseHeaders } from '../cors';
1919
import { getMaxTeamSize, getTeamMemberData, getUserId } from '../user-data';
2020
import { getSku, isTeamSubscription } from '../products';
21+
import { mailer } from '../email';
2122

2223
const BearerRegex = /^Bearer (\S+)$/;
2324

@@ -57,6 +58,7 @@ export const handler = catchErrors(async (event) => {
5758
getTeamMemberData(ownerId)
5859
]);
5960

61+
const ownerEmail = userData.email;
6062
const ownerData = userData.app_metadata as TeamOwnerMetadata;
6163

6264
const sku = getSku(ownerData);
@@ -143,6 +145,11 @@ export const handler = catchErrors(async (event) => {
143145
locked_licenses: updatedLicenseLocks
144146
} as TeamOwnerMetadata);
145147

148+
// Send invite emails to all newly added team members:
149+
await Promise.all(
150+
emailsToAdd.map((email) => sendTeamInviteEmail(email, ownerEmail))
151+
);
152+
146153
return { statusCode: 200, headers, body: 'success' };
147154
} catch (e: any) {
148155
await reportError(e);
@@ -300,4 +307,33 @@ function checkUserCanJoinTeams(ownerId: string, user: User): true {
300307

301308
// We leave a little margin on expiry checks, so that tiny delays in webhook
302309
// delivery don't leave users in weird limbo.
303-
const SUB_EXPIRY_MARGIN_MS = 1000 * 60;
310+
const SUB_EXPIRY_MARGIN_MS = 1000 * 60;
311+
312+
export async function sendTeamInviteEmail(email: string, ownerEmail: string) {
313+
const subject = "You've been added to an HTTP Toolkit Team";
314+
const html = `
315+
<html>
316+
<body style="font-family: sans-serif; background: #e4e8ed; color: #1e2028; text-align: center; padding: 40px 10px;">
317+
<div style="max-width: 480px; margin: 0 auto; background: #fafafa; border-radius: 8px; box-shadow: 0 2px 8px #9a9da8; padding: 32px 24px;">
318+
<p><img src="https://httptoolkit.com/logo-text-1000.png" alt="HTTP Toolkit Logo" width="250" /></p>
319+
<h2 style="color: #e1421f;">Welcome to your HTTP Toolkit Team!</h2>
320+
<p style="font-size: 1.1em;">You've been added to a team subscription by ${_.escape(ownerEmail)}. You now have access to all HTTP Toolkit Pro features.</p>
321+
<p style="font-size: 1.1em;">To get started:</p>
322+
<ol style="text-align: left; margin: 0 auto; display: inline-block; font-size: 1.1em;">
323+
<li>Open HTTP Toolkit and click <b>Get Pro</b>.</li>
324+
<li>Click <b>Log into existing account</b>.</li>
325+
<li>Enter your email address (<b>${_.escape(email)}</b>).</li>
326+
</ol>
327+
<p style="margin-top: 2em; color: #888; font-size: 0.95em;">If you have any trouble, get in touch at <a href="mailto:[email protected]">[email protected]</a> or
328+
reach out to your team administrator at <b>${_.escape(ownerEmail)}</b>.</p>
329+
</div>
330+
</body>
331+
</html>
332+
`;
333+
await mailer.sendMail({
334+
from: 'HTTP Toolkit <[email protected]>',
335+
to: email,
336+
subject,
337+
html
338+
});
339+
}

0 commit comments

Comments
 (0)