{"record":{"id":"cd9151b82696236e","repo":"jstedfast/MailKit","slug":"smtpstatuscode-transactionfailed","errorCode":"SmtpStatusCode.TransactionFailed","errorMessage":"No recipients were accepted.","messagePattern":"No recipients were accepted\\.","errorType":"exception","errorClass":"SmtpCommandException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Smtp/SmtpClient.cs","lineNumber":2478,"sourceCode":"\t\t\t\t\tif (RcptTo (format, message, recipients[i], pipeline, cancellationToken))\n\t\t\t\t\t\trecipientsAccepted++;\n\t\t\t\t}\n\n\t\t\t\tif (queued.Count > 0) {\n\t\t\t\t\t// Note: if PIPELINING is supported, this will flush all outstanding\n\t\t\t\t\t// MAIL FROM and RCPT TO commands to the server and then process\n\t\t\t\t\t// all of their responses.\n\t\t\t\t\tvar results = FlushCommandQueue (message, sender, recipients, cancellationToken);\n\n\t\t\t\t\trecipientsAccepted = results.RecipientsAccepted;\n\n\t\t\t\t\tif (results.FirstException != null)\n\t\t\t\t\t\tthrow results.FirstException;\n\t\t\t\t}\n\n\t\t\t\tif (recipientsAccepted == 0) {\n\t\t\t\t\tOnNoRecipientsAccepted (message);\n\t\t\t\t\tthrow new SmtpCommandException (SmtpErrorCode.MessageNotAccepted, SmtpStatusCode.TransactionFailed, \"No recipients were accepted.\");\n\t\t\t\t}\n\n\t\t\t\tif (bdat)\n\t\t\t\t\treturn Bdat (format, message, size, cancellationToken, progress);\n\n\t\t\t\tvar dataResponse = Stream.SendCommand (\"DATA\\r\\n\", cancellationToken);\n\n\t\t\t\tParseDataResponse (dataResponse);\n\n\t\t\t\treturn MessageData (format, message, size, cancellationToken, progress);\n\t\t\t} catch (ServiceNotAuthenticatedException ex) {\n\t\t\t\toperation.SetError (ex);\n\n\t\t\t\t// do not disconnect\n\t\t\t\tReset (cancellationToken);\n\t\t\t\tthrow;\n\t\t\t} catch (SmtpCommandException ex) {\n\t\t\t\toperation.SetError (ex);","sourceCodeStart":2460,"sourceCodeEnd":2496,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Smtp/SmtpClient.cs#L2460-L2496","documentation":"SmtpCommandException (SmtpErrorCode.MessageNotAccepted, SmtpStatusCode.TransactionFailed) thrown when every RCPT TO was rejected by the server, so the MAIL transaction cannot proceed. MailKit raises NoRecipientsAccepted first, then throws. Note this differs from the local validation error: here the server refused the recipients.","triggerScenarios":"Calling Send/SendAsync where all RCPT TO commands receive rejections (nonexistent mailboxes, relay denied, no auth for relay, greylisted/over-quota recipients); using explicit sender/recipients overrides that contain bad addresses; a server that rejects unknown domains during RCPT.","commonSituations":"Typo'd or expired recipient addresses; relaying through a server that doesn't accept your domain without SMTP AUTH; bulk-sending to stale lists where every address in one message bounces; authenticated user lacks relay permission to external domains.","solutions":["Subscribe to MessageSent / check the recipient results, or use Send with explicit recipient list and validate addresses first.","Catch SmtpCommandException, inspect StatusCode/StatusLine, and remove or fix rejected recipients.","Ensure client.Authenticate succeeded — most 'relay access denied' rejections are unauthenticated relay attempts.","Verify recipient domains have valid MX records before sending.","Check OnNoRecipientsAccepted/NoRecipientsAccepted event to log server-side rejection reasons."],"exampleFix":"// before\nclient.Send(message); // throws if all recipients rejected\n// after\ntry {\n\tclient.Send(message);\n} catch (SmtpCommandException ex) when (ex.ErrorCode == SmtpErrorCode.MessageNotAccepted) {\n\tlogger.LogWarning(\"All recipients rejected: {0}\", ex.Message);\n\t// remove/fix recipients and retry\n}","handlingStrategy":"try-catch","validationCode":"if (recipients == null || recipients.Count == 0)\n\tthrow new InvalidOperationException(\"No recipients\");\nforeach (var r in recipients)\n\tif (!System.Text.RegularExpressions.Regex.IsMatch(r.Address ?? \"\", @\"^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$\"))\n\t\tthrow new InvalidOperationException(\"Bad recipient: \" + r);","typeGuard":"bool HasValidRecipients(IEnumerable<MailboxAddress> rcpts) =>\n\trcpts != null && rcpts.Any(r => !string.IsNullOrEmpty(r.Address));","tryCatchPattern":"try { client.Send(message); }\ncatch (SmtpCommandException ex) when (ex.ErrorCode == SmtpErrorCode.MessageNotAccepted && ex.StatusCode == SmtpStatusCode.TransactionFailed) {\n\t// log ex.Message, prune recipients, optionally re-send\n}","preventionTips":["Authenticate before sending — relay denial is a common cause.","Prune stale addresses from mailing lists.","Check the NoRecipientsAccepted event for server-side reasons.","Use per-message recipients you control rather than blind bulk overrides."],"tags":["smtp","mailkit","recipient-rejected","transaction-failed"],"backgroundTag":"smtp-transaction-failed","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}