Skip to content

Commit 6702787

Browse files
committed
updates for accept banner immage
1 parent 8d8cf28 commit 6702787

14 files changed

+527
-68
lines changed

db/connection.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ const dbConnection = new Pool({
1111
database: process.env.DB_NAME,
1212
password: process.env.DB_PASSWORD,
1313
port: parseInt(process.env.DB_PORT || '5432'),
14-
ssl: true
14+
ssl: {
15+
rejectUnauthorized: false
16+
}
1517
})
1618

1719
export default dbConnection

mail/emailConfig.ts

+11
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,19 @@ const transporter = nodemailer.createTransport({
1111
user: process.env.EMAIL_USER,
1212
pass: process.env.EMAIL_PASSWORD,
1313
},
14+
tls: {
15+
rejectUnauthorized: false
16+
}
1417
})
1518

19+
transporter.verify(function(error, success) {
20+
if (error) {
21+
console.log('Erro na verificação:', error);
22+
} else {
23+
console.log('Servidor pronto para enviar mensagens');
24+
}
25+
});
26+
1627
export const enviarEmail = async (para: string, assunto: string, corpo: string) => {
1728
try {
1829
await transporter.sendMail({

mail/emailService.ts

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import nodemailer from 'nodemailer';
2+
import sgMail from '@sendgrid/mail';
3+
import dotenv from 'dotenv';
4+
5+
dotenv.config();
6+
7+
// Configuração do provedor de email atual
8+
const EMAIL_PROVIDER = process.env.EMAIL_PROVIDER || 'nodemailer'; // 'nodemailer' ou 'sendgrid'
9+
10+
// Configuração do SendGrid
11+
if (EMAIL_PROVIDER === 'sendgrid') {
12+
sgMail.setApiKey(process.env.SENDGRID_API_KEY || '');
13+
}
14+
15+
// Configuração do Nodemailer
16+
const transporter = nodemailer.createTransport({
17+
host: process.env.EMAIL_HOST,
18+
port: parseInt(process.env.EMAIL_PORT || '587'),
19+
secure: false,
20+
auth: {
21+
user: process.env.EMAIL_USER,
22+
pass: process.env.EMAIL_PASSWORD,
23+
},
24+
tls: {
25+
rejectUnauthorized: false
26+
}
27+
});
28+
29+
export const enviarEmail = async (para: string, assunto: string, corpo: string) => {
30+
try {
31+
if (EMAIL_PROVIDER === 'sendgrid') {
32+
const msg = {
33+
to: para,
34+
from: process.env.EMAIL_FROM || '',
35+
subject: assunto,
36+
html: corpo,
37+
};
38+
await sgMail.send(msg);
39+
} else {
40+
await transporter.sendMail({
41+
from: process.env.EMAIL_FROM,
42+
to: para,
43+
subject: assunto,
44+
html: corpo,
45+
});
46+
}
47+
console.log('E-mail enviado com sucesso');
48+
} catch (erro) {
49+
console.error('Erro ao enviar e-mail:', erro);
50+
throw erro;
51+
}
52+
}
53+
54+
export default enviarEmail;

0 commit comments

Comments
 (0)