From c398484cf8741215e25dc1f4e66ab646aedf5630 Mon Sep 17 00:00:00 2001 From: m5r Date: Sat, 30 Oct 2021 14:31:22 +0200 Subject: [PATCH] welcome email --- app/auth/mutations/signup.ts | 8 +++- mailers/renderer.ts | 6 +-- mailers/templates/forgot-password.html | 10 ++--- mailers/templates/welcome.html | 53 ++++++++++++++++++++++++++ mailers/welcome-mailer.ts | 34 +++++++++++++++++ 5 files changed, 101 insertions(+), 10 deletions(-) create mode 100644 mailers/templates/welcome.html create mode 100644 mailers/welcome-mailer.ts diff --git a/app/auth/mutations/signup.ts b/app/auth/mutations/signup.ts index cde97df..d201b0d 100644 --- a/app/auth/mutations/signup.ts +++ b/app/auth/mutations/signup.ts @@ -3,6 +3,7 @@ import { resolver, SecurePassword } from "blitz"; import db, { GlobalRole, MembershipRole } from "db"; import { Signup } from "../validations"; import { computeEncryptionKey } from "db/_encryption"; +import { welcomeMailer } from "mailers/welcome-mailer"; export default resolver.pipe(resolver.zod(Signup), async ({ email, password, fullName }, ctx) => { const hashedPassword = await SecurePassword.hash(password.trim()); @@ -34,7 +35,12 @@ export default resolver.pipe(resolver.zod(Signup), async ({ email, password, ful shouldShowWelcomeMessage: true, }); - // TODO: send welcome email + await ( + await welcomeMailer({ + to: user.email, + userName: user.fullName, + }) + ).send(); return user; }); diff --git a/mailers/renderer.ts b/mailers/renderer.ts index 0a944ea..1274d7e 100644 --- a/mailers/renderer.ts +++ b/mailers/renderer.ts @@ -195,11 +195,9 @@ function getMaizzleParams(templateName: string, locals: Record) }, company: { name: "Capsule Corp. Dev Pte. Ltd.", - address: ` -
39 Robinson Rd, #11-01 -
Singapore 068911 - `, + address: `
39 Robinson Rd, #11-01
Singapore 068911`, product: "Shellphone", + sender: "Mokhtar", }, googleFonts: "family=Nunito+Sans:wght@400;700", year: () => new Date().getFullYear(), diff --git a/mailers/templates/forgot-password.html b/mailers/templates/forgot-password.html index 5b1bdf2..56daa24 100644 --- a/mailers/templates/forgot-password.html +++ b/mailers/templates/forgot-password.html @@ -16,11 +16,11 @@ bodyClass: bg-gray-postmark-lighter

- Hi {{name}}, + Hi {{ name }},

- You recently requested to reset your password for your - {{page.company.product}} account. Use the button below to reset it. + You recently requested to reset your password for your {{ page + .company.product}} account. Use the button below to reset it. This password reset is only valid for the next 24 hours. Reset your password - {{action_url}} + {{ action_url }}

diff --git a/mailers/templates/welcome.html b/mailers/templates/welcome.html new file mode 100644 index 0000000..eada062 --- /dev/null +++ b/mailers/templates/welcome.html @@ -0,0 +1,53 @@ +--- +bodyClass: bg-gray-postmark-lighter +--- + + + + + + + + + + diff --git a/mailers/welcome-mailer.ts b/mailers/welcome-mailer.ts new file mode 100644 index 0000000..0c78ed9 --- /dev/null +++ b/mailers/welcome-mailer.ts @@ -0,0 +1,34 @@ +import previewEmail from "preview-email"; + +import { sendEmail } from "integrations/aws-ses"; +import { render } from "./renderer"; + +type ResetPasswordMailer = { + to: string; + userName: string; +}; + +export async function welcomeMailer({ to, userName }: ResetPasswordMailer) { + const html = await render("welcome", { name: userName }); + const msg = { + from: "mokhtar@shellphone.app", + to, + subject: "Welcome to Shellphone", + html, + }; + + return { + async send() { + if (process.env.NODE_ENV === "production") { + await sendEmail({ + recipients: [msg.to], + subject: msg.subject, + html: msg.html, + }); + } else { + // Preview email in the browser + return await previewEmail(msg); + } + }, + }; +}