Reputation: 979
This application is WPF Windows application using C#,
I am trying to send email to a fairly long list of recipients. Let me state at the outset that this is not spam as these people have signed up for this list.
I am using smtpclient.sendasync. This works fine in testing when I send it to 1 to 3 people but when I send it to the whole mailing list, it fails to work. The number on the list is 2623. There is no error message; it’s just that the receipts don’t get the email. This is a problem to debug because I can’t test it by, for example, sending it to 100 people because that would be spamming.
See the code below. Note I changed the email addresses to prevent spamming.
Int32 _MessageCount = 0;
MailMessage msg = new MailMessage();
SmtpClient client = new SmtpClient(Configuration.smtpServer);
string _PriorEMail = "";
msg.From = new MailAddress("[email protected]");
msg.To.Add (new MailAddress("[email protected]"));
// bcc to the list
foreach (string str in EmailToAddresses)
{
if (clsUtilities.IsAnEmail(str) == true && str != _PriorEMail)
{ // process only valid emails and avoid dups
_MessageCount += 1;
msg.Bcc.Add(new MailAddress(str));
_PriorEMail = str;
}
}
msg.Subject = EmailSubject;
msg.IsBodyHtml = true;
msg.Body = EmailBodyHtml;
client.SendAsync(msg,null);
Upvotes: 1
Views: 1723
Reputation: 329
When sending e-mail using SendAsync to multiple recipients, if the SMTP server accepts some recipients as valid and rejects others, a SmtpException is thrown with a NullReferenceException for the inner exception. If this occurs, SendAsync fails to send e-mail to any of the recipients.
Upvotes: 0
Reputation: 8084
The limitation probably comes from the SMTP server itself: those are set-up to prevent sending emails to a huge amount of recipients, for various reasons (from legal through business to performance).
Check with the provider of the SMTP server for the actual limitation. Work around that by throttling the operation, and/or using an SMTP server which allows a greater number of recipients.
See this IIS documentation for example: it states that if the limit is 100, and your recipients list is 105 addresses long, only the first 100 addresses will be processed.
Upvotes: 2