package mailer import ( "bytes" "fmt" "log" "net/smtp" "os" "nucleus/internal/models" ) func SendReport(target models.Target, findings []models.Finding) { host := os.Getenv("SMTP_HOST") port := os.Getenv("SMTP_PORT") if host == "" || port == "" { log.Println("SMTP_HOST or SMTP_PORT not set, skipping email report.") return } user := os.Getenv("SMTP_USER") pass := os.Getenv("SMTP_PASS") from := os.Getenv("SMTP_FROM") to := os.Getenv("SMTP_TO") if from == "" || to == "" { log.Println("SMTP_FROM or SMTP_TO not set, skipping email report.") return } var auth smtp.Auth if user != "" && pass != "" { auth = smtp.PlainAuth("", user, pass, host) } subject := fmt.Sprintf("Nucleus Scan Report: %s", target.Name) var body bytes.Buffer body.WriteString(fmt.Sprintf("To: %s\r\n", to)) body.WriteString(fmt.Sprintf("From: %s\r\n", from)) body.WriteString(fmt.Sprintf("Subject: %s\r\n", subject)) body.WriteString("Content-Type: text/html; charset=UTF-8\r\n\r\n") body.WriteString("
") body.WriteString(fmt.Sprintf("The scheduled Nuclei scan has completed.
") if len(findings) == 0 { body.WriteString("No findings were detected.
") } else { body.WriteString("| Severity | Name | Host | Template |
|---|---|---|---|
| %s | %s | %s | %s |