jstedfast/MailKit · error · InvalidOperationException
No recipients have been specified.
Error message
No recipients have been specified.
What it means
Validation in SmtpClient.ValidateArguments: GetMessageRecipients found no To, Cc, Bcc (or Resent-* equivalents) addresses on the message, so there is no one to send it to (RCPT TO would have no recipients) and InvalidOperationException is thrown.
Solutions
- Add recipients before send.
- Use explicit recipients overload.
Example fix
null
Defensive patterns
Strategy: validation
Validate before calling
if (!(message.To.Any() || message.Cc.Any() || message.Bcc.Any()))
throw new InvalidOperationException("missing recipients"); Type guard
bool HasRecipients(MimeMessage m) => m.To?.Any() == true || m.Cc?.Any() == true || m.Bcc?.Any() == true;
Try / catch
catch (InvalidOperationException ex) when (ex.Message == "No recipients have been specified.") { /* dead-letter */ } Prevention
- Validate recipients at input boundary.
When it happens
Trigger: MimeMessage without To/Cc/Bcc.
Common situations: Empty recipient input from user data.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- No compatible authentication mechanisms found.
- No sender has been specified.
- null
- SmtpStatusCode.TransactionFailed
- The address cannot be empty.
AI-assisted analysis of jstedfast/MailKit@9d3859a785 (2026-09-15).
Data as JSON: /api/errors/800a361f47f05ab8.
Report an issue: GitHub.
Appendix: source
Thrown at MailKit/Net/Smtp/SmtpClient.cs:2526
static void ValidateArguments (FormatOptions options, MimeMessage message, out MailboxAddress sender, out IList<MailboxAddress> recipients)
{
if (options == null)
throw new ArgumentNullException (nameof (options));
if (message == null)
throw new ArgumentNullException (nameof (message));
var mailbox = GetMessageSender (message);
if (mailbox == null)
throw new InvalidOperationException ("No sender has been specified.");
sender = mailbox;
recipients = GetMessageRecipients (message);
if (recipients.Count == 0)
throw new InvalidOperationException ("No recipients have been specified.");
}
/// <summary>
/// Send the specified message.
/// </summary>
/// <remarks>
/// <para>Sends the specified message.</para>
/// <para>The sender address is determined by checking the following
/// message headers (in order of precedence): Resent-Sender,
/// Resent-From, Sender, and From.</para>
/// <para>If either the Resent-Sender or Resent-From addresses are present,
/// the recipients are collected from the Resent-To, Resent-Cc, and
/// Resent-Bcc headers, otherwise the To, Cc, and Bcc headers are used.</para>
/// </remarks>
/// <example>
/// <code language="c#" source="Examples\SmtpExamples.cs" region="SendMessageWithOptions"/>
/// </example>
/// <returns>The final free-form text response from the server.</returns>View on GitHub (pinned to 9d3859a785)