diff --git a/public/gdg-icon.png b/public/gdg-icon.png new file mode 100644 index 0000000..3f91ec5 Binary files /dev/null and b/public/gdg-icon.png differ diff --git a/src/app/api/email/route.ts b/src/app/api/email/route.ts index 3a3eec7..9be9870 100644 --- a/src/app/api/email/route.ts +++ b/src/app/api/email/route.ts @@ -1,48 +1,31 @@ -import { NextResponse } from 'next/server'; -import nodemailer from 'nodemailer'; -import Mail from 'nodemailer/lib/mailer'; +import { NextRequest, NextResponse } from "next/server"; +import { render } from "@react-email/render"; +import Email from "@/components/devfest24-email"; +import { handleSendEmail } from "@/lib/email"; -type Payload = { - to: string; - subject: string; - html: string; - attachments: Mail.Attachment[]; -}; - -export async function POST(request: Request) { +export async function POST(request: NextRequest) { try { - const data: Payload = await request.json(); + const body = await request.json(); + const { id, email, firstName, lastName } = body; - let transporter = nodemailer.createTransport({ - service: 'gmail', - auth: { - user: process.env.NODEMAILER_EMAIL, - pass: process.env.NODEMAILER_PW, - }, - }); + const htmlContent = await render(Email({ id, firstName, lastName })); - await new Promise((resolve, reject) => { - transporter.sendMail( - { - from: process.env.NODEMAILER_EMAIL, - ...data, - }, - (error, info) => { - if (error) { - console.error('Error sending email:', error); - reject(error); - } else { - console.log('Email sent:', info.response); - resolve(info); - } - } - ); + await handleSendEmail({ + to: email, + subject: "Certificate: Google DevFest 2024", + html: htmlContent, }); - return NextResponse.json({ message: 'Email sent successfully' }, { status: 200 }); - } catch (error) { - console.error('Error in route handler:', error); - return NextResponse.json({ error: 'Failed to send email' }, { status: 500 }); + return NextResponse.json({ message: "Success" }, { status: 200 }); + } catch (err: any) { + console.error("Error sending email:", err, process.env.NODEMAILER_PW); + return NextResponse.json({ message: err.message }, { status: 500 }); } } +export async function GET() { + return NextResponse.json( + { message: "GET request received" }, + { status: 200 }, + ); +} diff --git a/src/components/devfest24-email.tsx b/src/components/devfest24-email.tsx index 82da1f0..3135960 100644 --- a/src/components/devfest24-email.tsx +++ b/src/components/devfest24-email.tsx @@ -6,6 +6,8 @@ import { Heading, Hr, Html, + Img, + Link, Preview, Section, Tailwind, @@ -17,44 +19,109 @@ type Props = { id: string; firstName: string; lastName: string; + eventName?: string; }; -export const CertificateEmail = ({ id, firstName, lastName }: Props) => { - const previewText = "Claim Your Certificate!"; +export const CertificateEmail = ({ + id, + firstName, + lastName, + eventName = "DevFest Bacolod 2024", +}: Props) => { + const previewText = `Your ${eventName} Certificate is Ready!`; return ( {previewText} - - - - GDG Bacolod - - - Hello {firstName} {lastName}, + + +
+ GDG Bacolod Logo + + GDG Bacolod + +
+
+ Certificate Preview +
+ + Dear {firstName} {lastName}, - - We're excited to let you know that your certificate for{" "} - Google DevFest 2024 is ready and waiting for you. - 🎉 To claim it, just click the button below or check out the - attached image: + + Congratulations! 🎉 Your certificate for{" "} + {eventName} is now available. We're thrilled + to recognize your participation and achievement. -
+
-
- - This certificate generator is powered by{" "} - omsimos.com — If you were not - expecting this certificate, you can ignore this email. + + Don't forget to share your achievement on social media. + It's a great way to showcase your involvement in the tech + community! + + + We value your feedback! Please take a moment to share your + thoughts about the event: + +
+ + Provide Feedback + +
+
+ + This certificate is powered by{" "} + + omsimos.com + + + + If you didn't participate in this event, please disregard + this email. +
+ + Follow us on social media: + + + Facebook + + + LinkedIn + +
diff --git a/src/lib/email.ts b/src/lib/email.ts index 5766087..b1fafda 100644 --- a/src/lib/email.ts +++ b/src/lib/email.ts @@ -5,12 +5,18 @@ type Payload = { to: string; subject: string; html: string; - attachments: Mail.Attachment[]; + attachments?: Mail.Attachment[]; }; export const handleSendEmail = async (data: Payload) => { let transporter = nodemailer.createTransport({ - service: "gmail", + host: "smtp.hostinger.com", + port: 465, + secure: true, + debug: process.env.NODE_ENV === "development", + tls: { + rejectUnauthorized: false, + }, auth: { user: process.env.NODEMAILER_EMAIL, pass: process.env.NODEMAILER_PW, @@ -19,11 +25,12 @@ export const handleSendEmail = async (data: Payload) => { return ( await transporter.sendMail({ - from: process.env.NODEMAILER_EMAIL, + from: "no-reply@omsimos.com", ...data, }), function (error: string, _info: string) { if (error) { + console.log("Your Email", process.env.NODEMAILER_EMAIL); throw new Error(error); } else { console.log("Email Sent");