0 votes
by (8.4k points)

When using Smtp.Send method to send the e-mail below, a "One or more recipients rejected. Call SmtpException.GetRejectedRecipients() to get a collection of rejected email addresses" exception occurs. Why? And is there any way to make this work?

From: me@rebex.net
To: Undisclosed recipients:;
Bcc: support@rebex.net;sales@rebex.net
Subject: Sample subject
Content-Type: text/plain

Sample body

Communication log:

2017-04-06 12:42:03.852 INFO Smtp(1)[1] Command: MAIL FROM:<me@rebex.net> SIZE=173
2017-04-06 12:42:03.856 INFO Smtp(1)[1] Response: 250 2.1.0 me@rebex.net....Sender OK
2017-04-06 12:42:03.857 INFO Smtp(1)[1] Command: RCPT TO:<Undisclosed recipients:;> NOTIFY=FAILURE
2017-04-06 12:42:03.859 INFO Smtp(1)[1] Command: RCPT TO:<support@rebex.net> NOTIFY=FAILURE
2017-04-06 12:42:03.860 INFO Smtp(1)[1] Command: RCPT TO:<sales@rebex.net> NOTIFY=FAILURE
2017-04-06 12:42:03.860 INFO Smtp(1)[1] Response: 501 5.5.4 Invalid Address
2017-04-06 12:42:03.863 INFO Smtp(1)[1] Response: 250 2.1.5 support@rebex.net
2017-04-06 12:42:03.866 INFO Smtp(1)[1] Response: 250 2.1.5 sales@rebex.net
2017-04-06 12:42:03.866 INFO Smtp(1)[1] Command: RSET
2017-04-06 12:42:03.869 INFO Smtp(1)[1] Response: 250 2.0.0 Resetting
2017-04-06 12:42:03.873 ERROR Smtp(1)[1] Info: Rebex.Net.SmtpException: One or more recipients rejected. Call SmtpException.GetRejectedRecipients() to get a collection of rejected email addresses.
Applies to: Rebex Secure Mail
by (58.9k points)
This has been fixed as part of version 2017R3 of Rebex components.

1 Answer

0 votes
by (144k points)
edited by

UPDATE

The fix has been released as part of release 2017 R3 of Rebex components. Thanks for bringing this issue to our attention!


The Smtp object client tried sending an email to "Undisclosed recipients:;" mail address. This is used as a placeholder address when sending e-mail to multiple recipients and should have been skipped by the client. The server is behaving correctly and rejects the placeholder address.

We will fix this for the next release. In the meantime, either ask for a hotfix or use the following extension method instead of Smtp.Send as a workaround:

public static class SmtpHelper
{
    public static void SendFixed(this Smtp smtp, MailMessage mail)
    {
        // get list of all recipients
        var list = new MailAddressCollection();
        list.AddRange(mail.To);
        list.AddRange(mail.CC);
        list.AddRange(mail.Bcc);

        // construct recipient addresses string
        var recipients = new StringBuilder();
        foreach (MailAddress mailbox in list)
        {
            string address = mailbox.Address;

            // skip empty addresses
            if (string.IsNullOrWhiteSpace(address))
            {
                continue;
            }

            // detect and skip dummy 'undisclosed recipients' addresses
            if (address.IndexOf('@') < 0 && address.IndexOf(':') >= 0)
            {
                continue;
            }

            // reject addresses with colon which is used as a delimiter in the recipients string
            if (address.IndexOf(';') >= 0)
            {
                throw new SmtpException("Invalid address: " + address);
            }

            // add the address into the string
            recipients.Append(address);
            recipients.Append(';');
        }

        // fail if no recipients found
        if (recipients.Length == 0)
        {
            throw new SmtpException("No recipients found.");
        }

        smtp.Send(mail, null, recipients.ToString());
    }
}
...