开发者

smtpclient.sendasync fails to work with too many recipients

开发者 https://www.devze.com 2023-02-24 08:26 出处:网络
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 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 = ne开发者_运维技巧w SmtpClient(Configuration.smtpServer);
            string _PriorEMail = "";

            msg.From = new MailAddress("a@b.com");
            msg.To.Add (new MailAddress("a@b.com"));

            // 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);


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.


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.

Microsoft Site

0

精彩评论

暂无评论...
验证码 换一张
取 消