|
|
|
|
@@ -4,41 +4,41 @@ import nodemailer from "nodemailer";
|
|
|
|
|
import emailTemplate from "../templates/emailTemplate.html?raw";
|
|
|
|
|
|
|
|
|
|
const transporter = nodemailer.createTransport({
|
|
|
|
|
service: "gmail",
|
|
|
|
|
auth: {
|
|
|
|
|
user: import.meta.env.EMAIL_USER,
|
|
|
|
|
pass: import.meta.env.EMAIL_PASS,
|
|
|
|
|
},
|
|
|
|
|
service: "gmail",
|
|
|
|
|
auth: {
|
|
|
|
|
user: import.meta.env.EMAIL_USER,
|
|
|
|
|
pass: import.meta.env.EMAIL_PASS,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const server = {
|
|
|
|
|
sendEmail: defineAction({
|
|
|
|
|
input: z.object({
|
|
|
|
|
userName: z.string(),
|
|
|
|
|
companyName: z.string(),
|
|
|
|
|
phoneNumber: z.string(),
|
|
|
|
|
userEmail: z.string().email(),
|
|
|
|
|
}),
|
|
|
|
|
sendEmail: defineAction({
|
|
|
|
|
input: z.object({
|
|
|
|
|
userName: z.string(),
|
|
|
|
|
companyName: z.string(),
|
|
|
|
|
phoneNumber: z.string(),
|
|
|
|
|
userEmail: z.string().email(),
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
handler: async (input) => {
|
|
|
|
|
const mailOptions = {
|
|
|
|
|
from: '"Juan Diego" <jdcorreosvarios@gmail.com>',
|
|
|
|
|
to: "jdcorreosvarios@gmail.com",
|
|
|
|
|
subject: `Nueva persona interesada en Naliia: ${input.userName}`,
|
|
|
|
|
html: emailTemplate
|
|
|
|
|
.replace("{{userName}}", input.userName)
|
|
|
|
|
.replace("{{companyName}}", input.companyName)
|
|
|
|
|
.replace("{{phoneNumber}}", input.phoneNumber)
|
|
|
|
|
.replace("{{userEmail}}", input.userEmail),
|
|
|
|
|
};
|
|
|
|
|
handler: async (input) => {
|
|
|
|
|
const mailOptions = {
|
|
|
|
|
from: import.meta.env.EMAIL_FROM,
|
|
|
|
|
to: import.meta.env.EMAIL_TO,
|
|
|
|
|
subject: `Nueva persona interesada en Naliia: ${input.userName}`,
|
|
|
|
|
html: emailTemplate
|
|
|
|
|
.replace("{{userName}}", input.userName)
|
|
|
|
|
.replace("{{companyName}}", input.companyName)
|
|
|
|
|
.replace("{{phoneNumber}}", input.phoneNumber)
|
|
|
|
|
.replace("{{userEmail}}", input.userEmail),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await transporter.sendMail(mailOptions);
|
|
|
|
|
return { success: true };
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Error al enviar el correo:", error);
|
|
|
|
|
throw new Error("Error al enviar el correo");
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
try {
|
|
|
|
|
await transporter.sendMail(mailOptions);
|
|
|
|
|
return { success: true };
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Error al enviar el correo:", error);
|
|
|
|
|
throw new Error("Error al enviar el correo");
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
};
|
|
|
|
|
|