From dc4449ef899a9cdcb0b9d4608c7a121b1697d0bf Mon Sep 17 00:00:00 2001 From: aludayalu Date: Tue, 17 Oct 2023 15:59:17 +0530 Subject: [PATCH] mailing fix --- app/api/user/verify/route.ts | 75 ++++++++---------------------------- 1 file changed, 16 insertions(+), 59 deletions(-) diff --git a/app/api/user/verify/route.ts b/app/api/user/verify/route.ts index 30bc24b..763accf 100644 --- a/app/api/user/verify/route.ts +++ b/app/api/user/verify/route.ts @@ -1,6 +1,5 @@ import { NextRequest, NextResponse } from "next/server"; import jwt from "jsonwebtoken"; -import nodemailer from "nodemailer"; import client from "@/util/data/Mongo"; import { redirect } from "next/navigation"; @@ -90,52 +89,8 @@ export async function POST(req: NextRequest) { }); */ // Initialize nodemailer - const transporter = await nodemailer.createTransport({ - host: "smtp.gmail.com", - port: 465, - secure: true, - auth: { - user: process.env.GMAIL_USER, - pass: process.env.GMAIL_PASS, - }, - }); - - // verify connection configuration - await new Promise((resolve, reject) => { - transporter.verify(function (err, success) { - if (err) { - reject(err); - return new NextResponse(JSON.stringify(err)); - } else { - resolve(success); - } - }); - }); // Function to generate emailOptions - const emailOptions = (url: string, to: string, teacher: boolean) => { - return { - from: "Exun Clan ", - to: to, - subject: `Exun 2023 ${teacher ? "Teacher In-charge " : ""}Verification`, - html: ` -

- Please click on the following link to verify your email for Exun 2023.

- - ${url} - -

- This is your unique discord ${process.env - .DISCORD_INVITE_LINK!} verification token: ${randomToken} -
- Kindly share it with the participants of your school. -

- Regards,
- Exun Clan -

- `, - }; - }; // Sign jwt token if email exists if (email) { @@ -151,20 +106,22 @@ export async function POST(req: NextRequest) { ); const url = `${process.env.NEXT_PUBLIC_URL}/api/user/verify?token=${token}`; - - await new Promise((resolve, reject) => { - transporter.sendMail(emailOptions(url, email, false), (err, info) => { - if (err) { - reject(err); - return new NextResponse(JSON.stringify(err)); - } - - resolve(info); - - /* // For test account - console.log(nodemailer.getTestMessageUrl(_)); */ - }); - }); + await fetch(`https://exun-mailer.vercel.app/email?password=${"Tejas%20yaha%20password%20nhi%20milega%20tujhe%20iska%20sorry"}&to=${encodeURIComponent(email)}&subject=${encodeURIComponent(`Exun 2023 ${false ? "Teacher In-charge " : ""}Verification`)}&html=${` +

+ Please click on the following link to verify your email for Exun 2023.

+ + ${url} + +

+ This is your unique discord ${process.env + .DISCORD_INVITE_LINK!} verification token: ${randomToken} +
+ Kindly share it with the participants of your school. +

+ Regards,
+ Exun Clan +

+ `}`) } // Sign jwt token if teacherEmail exists