fix: add MAIL_FROM env (default mgmt@msbls.de) + graceful fallback when m CLI unavailable

This commit is contained in:
m
2026-03-30 17:10:25 +02:00
parent f51d189a3b
commit b21efccfb5

View File

@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log/slog"
"os"
"os/exec"
"strings"
"sync"
@@ -458,17 +459,25 @@ type UpdatePreferencesInput struct {
}
// SendEmail sends an email using the `m mail send` CLI command.
// In Docker, this will fail gracefully (m CLI not available).
// TODO: Replace with direct SMTP for production.
func SendEmail(to, subject, body string) error {
from := os.Getenv("MAIL_FROM")
if from == "" {
from = "mgmt@msbls.de"
}
cmd := exec.Command("m", "mail", "send",
"--from", from,
"--to", to,
"--subject", subject,
"--body", body,
"--yes")
output, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("m mail send failed: %w (output: %s)", err, string(output))
slog.Warn("email send failed (m CLI may not be available in Docker)", "to", to, "error", err, "output", string(output))
return fmt.Errorf("m mail send failed: %w", err)
}
slog.Info("email sent", "to", to, "subject", subject)
slog.Info("email sent", "from", from, "to", to, "subject", subject)
return nil
}