fix: add MAIL_FROM env (default mgmt@msbls.de) + graceful fallback when m CLI unavailable
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -458,17 +459,25 @@ type UpdatePreferencesInput struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SendEmail sends an email using the `m mail send` CLI command.
|
// 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 {
|
func SendEmail(to, subject, body string) error {
|
||||||
|
from := os.Getenv("MAIL_FROM")
|
||||||
|
if from == "" {
|
||||||
|
from = "mgmt@msbls.de"
|
||||||
|
}
|
||||||
cmd := exec.Command("m", "mail", "send",
|
cmd := exec.Command("m", "mail", "send",
|
||||||
|
"--from", from,
|
||||||
"--to", to,
|
"--to", to,
|
||||||
"--subject", subject,
|
"--subject", subject,
|
||||||
"--body", body,
|
"--body", body,
|
||||||
"--yes")
|
"--yes")
|
||||||
output, err := cmd.CombinedOutput()
|
output, err := cmd.CombinedOutput()
|
||||||
if err != nil {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user