From 5368343c13ae204b98d0bfe22a46a0a2c8d87ed6 Mon Sep 17 00:00:00 2001 From: Shrish Deshpande Date: Thu, 25 Apr 2024 16:55:51 +0530 Subject: [PATCH] Send rich email --- Resources/Views/signup.leaf | 51 +++++++++++++++++++ .../Controllers/Auth/SignupController.swift | 6 ++- Sources/App/configure.swift | 3 ++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/Resources/Views/signup.leaf b/Resources/Views/signup.leaf index e69de29..d589a55 100644 --- a/Resources/Views/signup.leaf +++ b/Resources/Views/signup.leaf @@ -0,0 +1,51 @@ + + + + + + Verification Code + + + +
+
+

Welcome to Thoda Core

+

Please use the following verification code:

+

#(code)

+
+ + +
+ + diff --git a/Sources/App/Controllers/Auth/SignupController.swift b/Sources/App/Controllers/Auth/SignupController.swift index d237ab1..184cc55 100644 --- a/Sources/App/Controllers/Auth/SignupController.swift +++ b/Sources/App/Controllers/Auth/SignupController.swift @@ -62,12 +62,16 @@ struct SignupController: RouteCollection { } let code = try await getOrGenerateConfirmationCode(jwt: payload.state, req: req) + + let emailBody: View = try await req.view.render("signup", ["code": code]) + let body = emailBody.data.getString(at: 0, length: emailBody.data.readableBytes) let email = try Email( from: EmailAddress(address: appConfig.smtp.email, name: "Thoda Core"), to: [EmailAddress(address: user.email, name: user.name)], subject: "Your verification code", - body: "Your verification code is: \(code)" + body: body ?? "Your verification code is \(code)", + isBodyHtml: true ) let sent = try await req.smtp.send(email) { message in diff --git a/Sources/App/configure.swift b/Sources/App/configure.swift index 601635a..f8af7b2 100644 --- a/Sources/App/configure.swift +++ b/Sources/App/configure.swift @@ -5,6 +5,7 @@ import Vapor import Smtp import Redis import JWT +import Leaf var appConfig: AppConfig = .init() @@ -59,6 +60,8 @@ public func configure(_ app: Application) async throws { app.routes.defaultMaxBodySize = "512kb" + app.views.use(.leaf) + // register routes try routes(app) }