diff --git a/rest/controllers/smtp_config_controller.go b/rest/controllers/smtp_config_controller.go index 6861224..932ac0d 100644 --- a/rest/controllers/smtp_config_controller.go +++ b/rest/controllers/smtp_config_controller.go @@ -86,6 +86,22 @@ func TestSmtpConfig(c *fiber.Ctx) error { if err := c.BodyParser(&body); err != nil || body.Email == "" { return c.Status(400).JSON(fiber.Map{"error": "Email de destino requerido"}) } + + // Recargar siempre la config activa desde BD para evitar usar credenciales + // del .env que pudieran estar desactualizadas en memoria. + cfg, err := models.GetSmtpConfig() + if err != nil { + return c.Status(500).JSON(fiber.Map{"error": "No hay configuración SMTP activa"}) + } + app.Http.Mail.Host = cfg.Host + app.Http.Mail.Port = cfg.Port + app.Http.Mail.Username = cfg.Username + app.Http.Mail.Password = utils.Decrypt(cfg.Password, app.Http.Server.Key) + app.Http.Mail.Encryption = cfg.Encryption + app.Http.Mail.FromAddress = cfg.FromAddress + app.Http.Mail.FromName = cfg.FromName + app.Http.Mail.SetupMailer() + htmlBody := "
La configuración SMTP funciona correctamente.
" if err := app.Http.Mail.Send(body.Email, "Test SMTP - U-site", htmlBody); err != nil { return c.Status(500).JSON(fiber.Map{"error": err.Error()})