{"record":{"id":"6027cabcab6d95c1","repo":"Billionmail/BillionMail","slug":"failed-to-send-alert-email-to-d-recipient-s-v","errorCode":null,"errorMessage":"failed to send alert email to %d recipient(s): %v","messagePattern":"failed to send alert email to (.+?) recipient\\(s\\): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/internal/service/domains/blacklist.go","lineNumber":507,"sourceCode":"\tvar failedRecipients []string\n\tfor _, recipient := range settings.RecipientList {\n\n\t\tmessage := mail_service.NewMessage(subject, body)\n\t\tmessage.SetRealName(settings.Name)\n\t\tmessageId := sender.GenerateMessageID()\n\t\tmessage.SetMessageID(messageId)\n\n\t\terr = sender.Send(message, []string{recipient})\n\t\tif err != nil {\n\t\t\tg.Log().Errorf(ctx, \"Failed to send alert email to %s: %v\", recipient, err)\n\t\t\tfailedRecipients = append(failedRecipients, recipient)\n\t\t} else {\n\t\t\tg.Log().Infof(ctx, \"Alert email sent successfully to %s\", recipient)\n\t\t}\n\t}\n\n\tif len(failedRecipients) > 0 {\n\t\treturn fmt.Errorf(\"failed to send alert email to %d recipient(s): %v\", len(failedRecipients), failedRecipients)\n\t}\n\n\treturn nil\n}\n\nfunc buildBlacklistAlertEmailHTML(ip, domain string, result *model.BlacklistCheckResult) string {\n\n\tvar blacklistItems string\n\tfor i, bl := range result.BlackList {\n\t\tblacklistItems += fmt.Sprintf(\"                <li><strong>%d. %s</strong> (Response: %s)</li>\\n\",\n\t\t\ti+1, bl.Blacklist, bl.Response)\n\t}\n\n\treturn fmt.Sprintf(`\n<!DOCTYPE html>\n<html lang=\"en\">\n\t<head>\n\t\t<meta charset=\"UTF-8\" />","sourceCodeStart":489,"sourceCodeEnd":525,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/service/domains/blacklist.go#L489-L525","documentation":"sendAlertEmail iterates settings.RecipientList, sending to each recipient and recording addresses whose Send() call fails. If any recipient failed, it returns 'failed to send alert email to %d recipient(s): %v' listing the count and the failed addresses. Note the connection already succeeded — this is a per-recipient delivery failure, and the successful recipients still got the alert.","triggerScenarios":"Called from sendBlacklistAlert when one or more recipient addresses are rejected by the SMTP server (550 no such user, 554 relay denied, greylisting, invalid address format, mailbox full) during the per-recipient Send loop.","commonSituations":"Typo'd or departed employee addresses in RecipientList; recipients on domains with strict SPF/DMARC rejecting the sender; SMTP relay refusing to relay for external domains; rate limiting after many alert recipients; alias addresses that no longer exist in the alias table.","solutions":["Review the failedRecipients list in the wrapped error and correct or remove invalid addresses from alert settings","Check the SMTP server logs for the exact rejection codes (550/551/554) per failed address","Ensure the sender domain has valid SPF/DKIM/DMARC so recipient servers accept the mail","Resend the alert to only the failed recipients after fixing the cause"],"exampleFix":"// before\nif len(failedRecipients) > 0 {\n\treturn fmt.Errorf(\"failed to send alert email to %d recipient(s): %v\", len(failedRecipients), failedRecipients)\n}\n// after\nif len(failedRecipients) > 0 {\n\treturn fmt.Errorf(\"failed to send alert email to %d/%d recipient(s): %v (subject=%q)\", len(failedRecipients), len(settings.RecipientList), failedRecipients, subject)\n}","handlingStrategy":"fallback","validationCode":"// validate recipient addresses before sending\nfor _, r := range settings.RecipientList {\n\tif _, err := mail.ParseAddress(r); err != nil {\n\t\treturn fmt.Errorf(\"invalid alert recipient %q: %w\", r, err)\n\t}\n}","typeGuard":"func validRecipients(rs []string) bool {\n\tfor _, r := range rs {\n\t\tif _, err := mail.ParseAddress(r); err != nil {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn len(rs) > 0\n}","tryCatchPattern":"err := sendAlertEmail(ctx, settings, subject, body)\nif err != nil && strings.Contains(err.Error(), \"failed to send alert email to\") {\n\t// partial failure: alert still reached some recipients;\n\t// parse failedRecipients from the message and retry only those\n}","preventionTips":["Prune stale/typo addresses from RecipientList regularly","Verify recipient mail servers accept the sender (SPF/DKIM/DMARC aligned)","Keep recipient lists short to avoid relay rate limits","On partial failure, resend only to the failed addresses rather than everyone"],"tags":["smtp","email","recipients"],"backgroundTag":"email-delivery-failed","analyzedSha":"fc36c76c050c3775c5e899faf7403cf0262d2744","analyzedAt":"2026-09-05T21:28:54.019Z","contentChangedAt":"2026-09-05T21:28:54.019Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}