From 29058ed571ce3eed382dfc92cdb790d599fa6141 Mon Sep 17 00:00:00 2001 From: Joywin Bennis <107112207+joywin2003@users.noreply.github.com> Date: Tue, 19 Nov 2024 20:43:33 +0530 Subject: [PATCH] refactor: remove unused email template and related mailer functions --- emails/email-template.tsx | 129 -------------------------------------- src/lib/resend-mailer.ts | 32 ---------- src/lib/sendMail.tsx | 38 ----------- 3 files changed, 199 deletions(-) delete mode 100644 emails/email-template.tsx delete mode 100644 src/lib/resend-mailer.ts delete mode 100644 src/lib/sendMail.tsx diff --git a/emails/email-template.tsx b/emails/email-template.tsx deleted file mode 100644 index d2f0df4..0000000 --- a/emails/email-template.tsx +++ /dev/null @@ -1,129 +0,0 @@ -import * as React from "react"; -import { - Body, - Container, - Head, - Html, - Preview, - Section, - Text, - Heading, - Button, -} from "@react-email/components"; - -interface EmailTemplateProps { - name: string; - email: string; - OTP: string; -} - -export const EmailTemplate = ({ name, OTP }: EmailTemplateProps) => ( - - - Your OTP for Tedx 2024 Email Verification - - - Tedx SJEC - Hello {name}, - - Thank you for registering for Tedx 2024. - - - Your One-Time Password (OTP) for email verification is: - -
- {OTP} -
- - Please enter this OTP to complete your registration. The OTP is valid - for 10 minutes. - -
- -
- Thank you! - - Tedx SJEC Team - -
- - -); - -export default EmailTemplate; - -const main = { - backgroundColor: "#ffffff", - fontFamily: "HelveticaNeue,Helvetica,Arial,sans-serif", - textAlign: "center" as const, -}; - -const container = { - backgroundColor: "#ffffff", - border: "1px solid #ddd", - borderRadius: "5px", - marginTop: "20px", - width: "480px", - maxWidth: "100%", - margin: "0 auto", - padding: "12% 6%", -}; - -const company = { - fontWeight: "bold", - fontSize: "18px", - textAlign: "center" as const, -}; - -const codeTitle = { - textAlign: "center" as const, -}; - -const codeDescription = { - textAlign: "center" as const, -}; - -const codeContainer = { - background: "rgba(0,0,0,.05)", - borderRadius: "4px", - margin: "16px auto 14px", - verticalAlign: "middle", - width: "280px", - maxWidth: "100%", -}; - -const codeStyle = { - color: "#000", - display: "inline-block", - paddingBottom: "8px", - paddingTop: "8px", - margin: "0 auto", - width: "100%", - textAlign: "center" as const, - letterSpacing: "8px", -}; - -const buttonContainer = { - margin: "27px auto", - width: "auto", -}; - -const button = { - backgroundColor: "red", - borderRadius: "3px", - fontWeight: "600", - color: "#fff", - textAlign: "center" as const, - padding: "12px 24px", - margin: "0 auto", -}; - -const paragraph = { - color: "#444", - letterSpacing: "0", - padding: "0 40px", - margin: "0", - textAlign: "center" as const, -}; diff --git a/src/lib/resend-mailer.ts b/src/lib/resend-mailer.ts deleted file mode 100644 index b2fd9dd..0000000 --- a/src/lib/resend-mailer.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { EmailTemplate } from "../../emails/email-template"; -import { ResendEmailOptions, sendEmail as SendEmailType } from "@/types"; -import { Resend } from "resend"; - -const resend = new Resend(process.env.RESEND_API_KEY); - -export async function MailUsingResend({ email, name, OTP }: SendEmailType) { - console.log(process.env.RESEND_API_KEY); - try { - const mailOptions: ResendEmailOptions = { - from: '"Tedx SJEC" ', - to: email, - subject: "Tedx SJEC - Your OTP for Email Verification", - react: EmailTemplate({ - name: name, - OTP: OTP, - email: email, - }), - text: `Hello ${name},\n\nThank you for registering for Tedx 2024.\n\nYour One-Time Password (OTP) for email verification is:\n\n${OTP}\n\nPlease enter this OTP to complete your registration. The OTP is valid for 10 minutes.\n\nThank you!\n\nTedx SJEC Team`, - }; - - const { data, error } = await resend.emails.send(mailOptions); - console.log(data, error); - if (error) { - return { error, status: 500 }; - } - - return { data, status: 200 }; - } catch (error) { - return { error, status: 500 }; - } -} diff --git a/src/lib/sendMail.tsx b/src/lib/sendMail.tsx deleted file mode 100644 index 7dc08ca..0000000 --- a/src/lib/sendMail.tsx +++ /dev/null @@ -1,38 +0,0 @@ -import { EmailTemplate } from "../../emails/email-template"; -import { renderAsync } from "@react-email/render"; -import { EmailOptions, sendEmail as SendEmailType } from "@/types"; -import nodemailer from "nodemailer"; - -export const sendEmail = async (options: SendEmailType) => { - try { - const transporter = nodemailer.createTransport({ - service: "gmail", - auth: { - user: process.env.GMAIL_USER, - pass: process.env.GMAIL_PASS, - }, - }); - - const emailHtml = await renderAsync( - , - ); - - const mailOptions: EmailOptions = { - from: `"Tedx SJEC" <${process.env.GMAIL_USER}>`, - to: options.email, - subject: "Tedx SJEC - Your OTP for Email Verification", - html: emailHtml, - text: `Hello ${options.name},\n\nThank you for registering for Tedx 2024.\n\nYour One-Time Password (OTP) for email verification is:\n\n${options.OTP}\n\nPlease enter this OTP to complete your registration. The OTP is valid for 10 minutes.\n\nThank you!\n\nTedx SJEC Team`, - }; - const mailResponse = await transporter.sendMail(mailOptions); - return { mailResponse, status: 200 }; - } catch (error) { - return { error, status: 500 }; - } -}; - -export default sendEmail;