Skip to content

Commit 076f35d

Browse files
committed
docs: change sendgrid for gmail
1 parent 6b17f6a commit 076f35d

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

email-api/src/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { env } from './config/env.js'
1010
const app = express()
1111

1212
app.set('port', env.PORT || 3000)
13+
app.set('trust proxy', 1);
1314

1415
app.use(cors())
1516
app.use(helmet())

email-api/src/mails/mailer.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,35 @@
1-
import sgMail from '@sendgrid/mail'
1+
import nodemailer from 'nodemailer' // Cambiamos la librería
2+
import { env } from '../config/env.js'
3+
4+
// Creamos el transportador con la configuración de Gmail
5+
const transporter = nodemailer.createTransport({
6+
service: 'gmail',
7+
auth: {
8+
user: env.EMAIL,
9+
pass: env.GOOGLE_APP_PASSWORD, // Aquí irá tu código de 16 letras
10+
},
11+
});
12+
13+
export const sendEmail = async ({ to, subject, html }) => {
14+
const mailOptions = {
15+
from: env.EMAIL,
16+
to,
17+
subject,
18+
html
19+
}
20+
21+
try {
22+
await transporter.sendMail(mailOptions);
23+
console.log("Email sent via Gmail App Password to:", to);
24+
} catch (err) {
25+
console.error("Gmail/Nodemailer error:", err.message);
26+
// Importante: No lanzamos el error (throw) para que el registro del usuario
27+
// en el controller no se detenga si el mail falla.
28+
}
29+
}
30+
31+
32+
/*import sgMail from '@sendgrid/mail'
233
import { env } from '../config/env.js'
334
435
sgMail.setApiKey(env.SENDGRID_API_KEY)
@@ -17,4 +48,4 @@ export const sendEmail = async ({ to, subject, html }) => {
1748
console.error("SendGrid error:", err.response?.body || err.message)
1849
throw err
1950
}
20-
}
51+
}*/

entregable4-frontend-2-main/src/utils/axios.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import store from '../reduxStore/store';
33
import { showNotification } from '../shared/Notification/notificationSlice';
44

55
const axios = axiosOriginal.create({
6-
baseURL: import.meta.env.VITE_API_URL
6+
baseURL: import.meta.env.VITE_API_URL,
7+
timeout: 15000 // Le damos 15 segundos para que Render despierte y el mailer responda
78
})
89

910
axios.interceptors.request.use(function (config) {

0 commit comments

Comments
 (0)