Update smtp_config_controller.go
This commit is contained in:
@@ -86,6 +86,22 @@ func TestSmtpConfig(c *fiber.Ctx) error {
|
|||||||
if err := c.BodyParser(&body); err != nil || body.Email == "" {
|
if err := c.BodyParser(&body); err != nil || body.Email == "" {
|
||||||
return c.Status(400).JSON(fiber.Map{"error": "Email de destino requerido"})
|
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 := "<h2>Test SMTP</h2><p>La configuración SMTP funciona correctamente.</p>"
|
htmlBody := "<h2>Test SMTP</h2><p>La configuración SMTP funciona correctamente.</p>"
|
||||||
if err := app.Http.Mail.Send(body.Email, "Test SMTP - U-site", htmlBody); err != nil {
|
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()})
|
return c.Status(500).JSON(fiber.Map{"error": err.Error()})
|
||||||
|
|||||||
Reference in New Issue
Block a user