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