{"record":{"id":"344f530e7fd4c5ad","repo":"Billionmail/BillionMail","slug":"smtp-write-w","errorCode":null,"errorMessage":"SMTP write: %w","messagePattern":"SMTP write: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/internal/service/mail_service/sending.go","lineNumber":434,"sourceCode":"\n\t// Set the recipients\n\t// RCPT TO\n\tfor _, to := range recipients {\n\t\tif err = e.client.Rcpt(to); err != nil {\n\t\t\treturn fmt.Errorf(\"SMTP rcpt: %w\", err)\n\t\t}\n\t}\n\n\t// Get a writer for the message body\n\tvar w io.WriteCloser\n\tw, err = e.client.Data()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"SMTP data: %w\", err)\n\t}\n\n\t// Write the message\n\tif _, err = w.Write(msg); err != nil {\n\t\treturn fmt.Errorf(\"SMTP write: %w\", err)\n\t}\n\n\t// Close the writer\n\tif err = w.Close(); err != nil {\n\t\treturn fmt.Errorf(\"SMTP close writer: %w\", err)\n\t}\n\n\treturn nil\n}\n\n// isSecure check if TLS connection is needed\nfunc (e *EmailSender) isSecure() bool {\n\t// usually,\n\t// port 465 is used for SMTP with SSL (implicit TLS)\n\t// port 587 is used for SMTP with STARTTLS (explicit TLS)\n\tif e.Port == \"465\" {\n\t\treturn true\n\t} else if e.Port == \"587\" {","sourceCodeStart":416,"sourceCodeEnd":452,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/service/mail_service/sending.go#L416-L452","documentation":"This error wraps a failure writing the raw message bytes to the DATA-phase io.WriteCloser returned by smtp.Client.Data(). The message body could not be transmitted over the connection, so delivery of this message fails. Typically caused by the connection being closed or reset mid-DATA by the peer.","triggerScenarios":"w.Write(msg) returned an error because the TCP connection was closed/reset by the server while streaming the message body, a TLS error occurred mid-stream, or the message exceeded size limits and the server aborted.","commonSituations":"Very large messages exceeding message_size_limit cause the server to drop the connection; unstable network between client and mail server; Postfix anvil or proxy timeouts on slow writers.","solutions":["Check mail logs for connection loss or size-limit rejections; raise message_size_limit if large mails are intended","Retry the send on a new connection; the write failure is usually terminal for the session","Verify stable network path and TLS handshake health between app and SMTP server","Check for line-dot-escaping issues in msg content that could corrupt the DATA stream"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if len(msg) > maxSupportedSize { // match server message_size_limit\n    return errors.New(\"message exceeds size limit\")\n}","typeGuard":null,"tryCatchPattern":"err := sender.Send(msg, recipients)\nif err != nil && strings.Contains(err.Error(), \"SMTP write\") {\n    // session is dead; reconnect and retry once\n    conn = reconnect()\n    err = sender.Send(msg, recipients)\n}","preventionTips":["Keep message sizes under the server's message_size_limit","Ensure stable network/TLS path to the SMTP server","Detect dead connections early with TCP keepalives","Retry on a fresh connection; a failed DATA write cannot be resumed"],"tags":["smtp","io-write","connection-reset"],"backgroundTag":"smtp-transaction-failed","analyzedSha":"fc36c76c050c3775c5e899faf7403cf0262d2744","analyzedAt":"2026-09-05T21:28:54.019Z","contentChangedAt":"2026-09-05T21:28:54.019Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}