Add SMTP test email endpoint and mail logs in admin settings

- POST /settings/test-email: send test email to diagnose SMTP config
- Admin settings: test email form + last 20 email logs with status/error

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-06-29 11:20:56 -05:00
co-authored by Claude Sonnet 4.6
parent b0ca6804fa
commit 1f3efb50da
2 changed files with 102 additions and 3 deletions
+18 -2
View File
@@ -1,14 +1,15 @@
import { Controller, Get, Patch, Body, UseGuards, Param, Res, Query } from '@nestjs/common';
import { Controller, Get, Post, Patch, Body, UseGuards, Param, Res, Query } from '@nestjs/common';
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
import { Response } from 'express';
import { SettingsService } from './settings.service';
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
import { EmailOtpService } from '../auth/email-otp.service';
import { MailService } from '../mail/mail.service';
@ApiTags('Settings')
@Controller('settings')
export class SettingsController {
constructor(private settings: SettingsService, private emailOtp: EmailOtpService) {}
constructor(private settings: SettingsService, private emailOtp: EmailOtpService, private mail: MailService) {}
@Get()
getGlobal() { return this.settings.getGlobal(); }
@@ -44,6 +45,21 @@ export class SettingsController {
return this.emailOtp.saveSmtpConfig(body);
}
@Post('test-email')
@UseGuards(JwtAuthGuard) @ApiBearerAuth()
async testEmail(@Body() body: { to: string }) {
await this.mail.tryMail(
body.to,
'Correo de prueba — ProsApp',
`<div style="font-family:sans-serif;padding:32px;max-width:480px;margin:auto">
<h2 style="color:#1e293b">✅ Configuración SMTP correcta</h2>
<p style="color:#64748b">Si recibes este correo, el servidor SMTP está funcionando correctamente en ProsApp.</p>
<p style="color:#94a3b8;font-size:12px">Enviado desde el panel de administración.</p>
</div>`,
);
return { message: `Correo de prueba enviado a ${body.to}` };
}
// Message logs
@Get('message-logs')
@UseGuards(JwtAuthGuard) @ApiBearerAuth()