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());
}
}