diff --git a/package-lock.json b/package-lock.json index ee22547..ab88392 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,11 @@ "version": "0.0.1", "dependencies": { "astro": "^5.17.1", - "lenis": "^1.3.17" + "lenis": "^1.3.17", + "nodemailer": "^8.0.1" + }, + "devDependencies": { + "@types/nodemailer": "^7.0.11" } }, "node_modules/@astrojs/compiler": { @@ -1513,6 +1517,26 @@ "@types/unist": "*" } }, + "node_modules/@types/node": { + "version": "25.3.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-25.3.0.tgz", + "integrity": "sha512-4K3bqJpXpqfg2XKGK9bpDTc6xO/xoUP/RBWS7AtRMug6zZFaRekiLzjVtAoZMquxoAbzBvy5nxQ7veS5eYzf8A==", + "devOptional": true, + "license": "MIT", + "dependencies": { + "undici-types": "~7.18.0" + } + }, + "node_modules/@types/nodemailer": { + "version": "7.0.11", + "resolved": "https://registry.npmjs.org/@types/nodemailer/-/nodemailer-7.0.11.tgz", + "integrity": "sha512-E+U4RzR2dKrx+u3N4DlsmLaDC6mMZOM/TPROxA0UAPiTgI0y4CEFBmZE+coGWTjakDriRsXG368lNk1u9Q0a2g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/unist": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.3.tgz", @@ -3675,6 +3699,15 @@ "integrity": "sha512-8DY+kFsDkNXy1sJglUfuODx1/opAGJGyrTuFqEoN90oRc2Vk0ZbD4K2qmKXBBEhZQzdKHIVfEJpDU8Ak2NJEvQ==", "license": "MIT" }, + "node_modules/nodemailer": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-8.0.1.tgz", + "integrity": "sha512-5kcldIXmaEjZcHR6F28IKGSgpmZHaF1IXLWFTG+Xh3S+Cce4MiakLtWY+PlBU69fLbRa8HlaGIrC/QolUpHkhg==", + "license": "MIT-0", + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/normalize-path": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", @@ -4495,6 +4528,13 @@ "integrity": "sha512-Ql87qFHB3s/De2ClA9e0gsnS6zXG27SkTiSJwjCc9MebbfapQfuPzumMIUMi38ezPZVNFcHI9sUIepeQfw8J8Q==", "license": "MIT" }, + "node_modules/undici-types": { + "version": "7.18.2", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.18.2.tgz", + "integrity": "sha512-AsuCzffGHJybSaRrmr5eHr81mwJU3kjw6M+uprWvCXiNeN9SOGwQ3Jn8jb8m3Z6izVgknn1R0FTCEAP2QrLY/w==", + "devOptional": true, + "license": "MIT" + }, "node_modules/unified": { "version": "11.0.5", "resolved": "https://registry.npmjs.org/unified/-/unified-11.0.5.tgz", diff --git a/package.json b/package.json index b9d8288..99c62f1 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,10 @@ }, "dependencies": { "astro": "^5.17.1", - "lenis": "^1.3.17" + "lenis": "^1.3.17", + "nodemailer": "^8.0.1" + }, + "devDependencies": { + "@types/nodemailer": "^7.0.11" } } diff --git a/src/actions/index.ts b/src/actions/index.ts new file mode 100644 index 0000000..8e1d719 --- /dev/null +++ b/src/actions/index.ts @@ -0,0 +1,44 @@ +import { defineAction } from "astro:actions"; +import { z } from "astro:schema"; +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, + }, +}); + +export const server = { + 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" ', + 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), + }; + + 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"); + } + }, + }), +}; diff --git a/src/pages/contact.astro b/src/pages/contact.astro index 0c6e8ee..6bc210c 100644 --- a/src/pages/contact.astro +++ b/src/pages/contact.astro @@ -103,7 +103,7 @@ import "../styles/contactpage.css"; name="contact-form" >
- @@ -111,12 +111,16 @@ import "../styles/contactpage.css"; type="text" class="form-input" placeholder="Juan Carlos Garcia Velez" + name="userName" + id="userName" required />
- @@ -124,12 +128,16 @@ import "../styles/contactpage.css"; type="text" class="form-input" placeholder="Empresa XYZ S.A.S" + name="companyName" + id="companyName" required />
- @@ -137,12 +145,16 @@ import "../styles/contactpage.css"; type="tel" class="form-input" placeholder="3104567890" + name="phoneNumber" + id="phoneNumber" required />
- @@ -150,6 +162,8 @@ import "../styles/contactpage.css"; type="email" class="form-input" placeholder="correoejemplo@gmail.com" + name="userEmail" + id="userEmail" required />
@@ -170,3 +184,40 @@ import "../styles/contactpage.css"; + + diff --git a/src/templates/emailTemplate.html b/src/templates/emailTemplate.html new file mode 100644 index 0000000..77082ff --- /dev/null +++ b/src/templates/emailTemplate.html @@ -0,0 +1,10 @@ +

Hay una nueva persona interesada en los servicios de Naliia:

+ +

Información de contacto:

+ +