{"record":{"id":"5a11a0bc74db7be7","repo":"jstedfast/MailKit","slug":"messagenotaccepted","errorCode":"MessageNotAccepted","errorMessage":"No recipients were accepted.","messagePattern":"No recipients were accepted\\.","errorType":"error_code","errorClass":"SmtpCommandException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Smtp/AsyncSmtpClient.cs","lineNumber":1015,"sourceCode":"\t\t\t\t\tif (await RcptToAsync (format, message, recipients[i], pipeline, cancellationToken).ConfigureAwait (false))\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 = await FlushCommandQueueAsync (message, sender, recipients, cancellationToken).ConfigureAwait (false);\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 await BdatAsync (format, message, size, cancellationToken, progress).ConfigureAwait (false);\n\n\t\t\t\tvar dataResponse = await Stream.SendCommandAsync (\"DATA\\r\\n\", cancellationToken).ConfigureAwait (false);\n\n\t\t\t\tParseDataResponse (dataResponse);\n\n\t\t\t\treturn await MessageDataAsync (format, message, size, cancellationToken, progress).ConfigureAwait (false);\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\tawait ResetAsync (cancellationToken).ConfigureAwait (false);\n\t\t\t\tthrow;\n\t\t\t} catch (SmtpCommandException ex) {\n\t\t\t\toperation.SetError (ex);","sourceCodeStart":997,"sourceCodeEnd":1033,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Smtp/AsyncSmtpClient.cs#L997-L1033","documentation":"During SendAsync, after RCPT TO is issued for each recipient, MailKit counts how many were accepted. If zero recipients were accepted by the server, it fires OnNoRecipientsAccepted and throws SmtpCommandException with SmtpStatusCode.TransactionFailed and this message, because the DATA/BDAT phase cannot proceed without at least one recipient.","triggerScenarios":"Calling SendAsync when every RCPT TO was rejected - e.g. Message.To/Cc/Bcc all empty, all recipients invalid, relay denied, or server rejecting each address with a permanent error.","commonSituations":"Sending mail where the recipient list was filtered to empty beforehand; authenticated user lacks relay permission; domain not accepted by the server; anti-spam rejection of all recipients.","solutions":["Inspect the RCPT TO failures (SmtpClient.RecipientsAccepted / the per-recipient exceptions) to see why each was rejected.","Verify the message has valid recipients in To/Cc/Bcc before sending.","Ensure SMTP authentication succeeded and the account has relay rights.","Handle the SmtpCommandException (code MessageNotAccepted) and check NoRecipientsAccepted event details."],"exampleFix":"// before\nawait client.SendAsync(message); // message.To is empty\n// after\nif (!message.To.Any() && !message.Cc.Any() && !message.Bcc.Any())\n    throw new InvalidOperationException(\"Message has no recipients\");\nawait client.SendAsync(message);","handlingStrategy":"validation","validationCode":"bool hasRecipients = message.To.Count + message.Cc.Count + message.Bcc.Count > 0;\nif (!hasRecipients)\n    throw new InvalidOperationException(\"Cannot send: message has no recipients\");","typeGuard":"bool HasValidRecipients(MimeMessage m) => m != null && (m.To.Any(a => a is MailboxAddress mb && MailboxAddress.IsValid(mb.Address)) || m.Cc.Any() || m.Bcc.Any());","tryCatchPattern":"try {\n    await client.SendAsync(message);\n} catch (SmtpCommandException ex) when (ex.ErrorCode == SmtpErrorCode.MessageNotAccepted) {\n    logger.LogWarning(\"All recipients rejected: {Message}\", ex.Message);\n    // inspect per-recipient failures / NoRecipientsAccepted event data before retrying\n}","preventionTips":["Validate recipients with MailboxAddress.TryParse before sending","Ensure authentication succeeded so the server permits relay","Subscribe to the NoRecipientsAccepted event for diagnostics","Check per-recipient RCPT failures instead of assuming all-or-nothing"],"tags":["smtp","recipients","send","async"],"backgroundTag":"smtp-recipient-rejected","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"}