feat: enhance email handling with improved error reporting and statistics
- Updated the `reenviarEmail` mutation to return detailed error messages for better user feedback. - Added a new query to obtain email queue statistics, providing insights into email statuses. - Enhanced the `processarFilaEmails` mutation to track processing failures and successes more effectively. - Implemented a manual email processing mutation for immediate testing and control over email sending. - Improved email validation and error handling in the email sending action, ensuring robust delivery processes.
This commit is contained in:
@@ -50,28 +50,48 @@ export const enviar = action({
|
||||
host: config.servidor,
|
||||
port: config.porta,
|
||||
secure: config.usarSSL,
|
||||
requireTLS: config.usarTLS,
|
||||
auth: {
|
||||
user: config.usuario,
|
||||
pass: config.senha, // Senha já descriptografada
|
||||
},
|
||||
tls: {
|
||||
// Permitir certificados autoassinados
|
||||
// Permitir certificados autoassinados apenas se necessário
|
||||
rejectUnauthorized: false,
|
||||
ciphers: "SSLv3",
|
||||
},
|
||||
connectionTimeout: 10000, // 10 segundos
|
||||
greetingTimeout: 10000,
|
||||
socketTimeout: 10000,
|
||||
});
|
||||
|
||||
// Validar email destinatário antes de enviar
|
||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
if (!emailRegex.test(email.destinatario)) {
|
||||
throw new Error(`Email destinatário inválido: ${email.destinatario}`);
|
||||
}
|
||||
|
||||
// Enviar email
|
||||
const info = await transporter.sendMail({
|
||||
from: `"${config.nomeRemetente}" <${config.emailRemetente}>`,
|
||||
to: email.destinatario,
|
||||
subject: email.assunto,
|
||||
html: email.corpo,
|
||||
text: email.corpo.replace(/<[^>]*>/g, ""), // Versão texto para clientes que não suportam HTML
|
||||
});
|
||||
|
||||
interface MessageInfo {
|
||||
messageId?: string;
|
||||
response?: string;
|
||||
}
|
||||
|
||||
const messageInfo = info as MessageInfo;
|
||||
|
||||
console.log("✅ Email enviado com sucesso!", {
|
||||
para: email.destinatario,
|
||||
assunto: email.assunto,
|
||||
messageId: (info as { messageId?: string }).messageId,
|
||||
messageId: messageInfo.messageId,
|
||||
response: messageInfo.response,
|
||||
});
|
||||
|
||||
// Marcar como enviado
|
||||
|
||||
@@ -42,8 +42,11 @@ export const testarConexao = action({
|
||||
pass: args.senha,
|
||||
},
|
||||
tls: {
|
||||
rejectUnauthorized: !args.usarTLS ? false : false,
|
||||
rejectUnauthorized: false,
|
||||
},
|
||||
connectionTimeout: 10000, // 10 segundos
|
||||
greetingTimeout: 10000,
|
||||
socketTimeout: 10000,
|
||||
});
|
||||
|
||||
// Verificar conexão
|
||||
|
||||
Reference in New Issue
Block a user