contact form via discord

This commit is contained in:
Owen Rees
2023-11-27 09:16:46 +01:00
parent 95ae9eb13d
commit d56d81a227
6 changed files with 125 additions and 147 deletions
+18 -22
View File
@@ -1,7 +1,5 @@
import NodeMailer from "nodemailer";
import { contactUsSchema } from "@/schemas";
import { errorLog, infoLog } from "@/utils/logger";
import { errorLog } from "@/utils/logger";
import { publicProcedure } from "../trpc";
@@ -10,27 +8,25 @@ export const contactUs = publicProcedure
.mutation(async ({ input }) => {
try {
const { email, subject, message } = input;
const mailContent = {
from: email,
to: process.env.GMAIL_USER,
subject: `${subject} from ${email}`,
text: message,
html: `<p>${message}</p>`,
};
const transporter = NodeMailer.createTransport({
service: "gmail",
auth: {
user: process.env.GMAIL_USER,
pass: process.env.GMAIL_PASS,
await fetch(process.env.DISCORD_WEBHOOK_CONTACT_URL as string, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
embeds: [
{
title: "Contact",
fields: [
{ name: "Email", value: email },
{ name: "Subject", value: subject },
{ name: "Message", value: message },
],
},
],
}),
});
const mailInfo = await transporter.sendMail(mailContent);
infoLog(mailInfo);
return true;
return true
} catch (error) {
errorLog(error);
throw error;