Search code examples
c#asp.netemailsmtpsmtpclient

Unable to send to a recipient : c# exception


Introduction

I am working on application module which suppose to send more than 1000 emails to users on list....

Problem

the code which is responsible of sending emails works fine for first 100 email but then throws an exception on this function,

smtp.Send(mail);

I been trying to figure out whats wrong, i have tried several techniques(like creating delay in sending emails, i.e: chunks of 50 emails per minute) but when count reaches about 100 email,,,, i experiences this exception....

Code

m.From = new MailAddress("[email protected]", "abc");
                m.To.Add(new MailAddress(to, ""));
                m.Subject = subject;
                m.IsBodyHtml = true;

                var fromAddress = m.From.Address.ToString();

                var toAddress = to;
                const string fromPassword = "*****";
                //string body = "From: " + message + "\n";
                //body = message;
                var smtp = new System.Net.Mail.SmtpClient();
                {
                    smtp.Host = "smtp.gmail.com";
                    smtp.Port = 587;
                    smtp.EnableSsl = true;
                    smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                    smtp.UseDefaultCredentials = false;
                    smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
                    // smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
                    smtp.Timeout = 200000;
                }
                smtp.Send(m);

Exception

System.Net.Mail.SmtpFailedRecipientsException was caught
      HResult=-2146233088
      Message=Unable to send to a recipient.
      Source=System
      FailedRecipient=<[email protected]>
      StackTrace:
           at System.Net.Mail.SmtpClient.Send(MailMessage message)
           at FlexiAnalysisLib.Common.MailHelper.AnalysisEmailViaAlternateView(String to, String subject, MailMessage m) in c:\beta development\FlexiAnalysisLib\Common\MailHelper.cs:line 553
      InnerException: System.Net.Mail.SmtpFailedRecipientException
           HResult=-2146233088
           Message=Insufficient system storage. The server response was: 4.5.3 Your message has too many recipients. For more information regarding
           FailedRecipient=<[email protected]>

If anyone have idea about the problem, please help...

Any kind of help or reference will be appreciated.... Thanks for your time


Solution

  • This is a limit imposed by whatever email service you're using.

    Google has a support page regarding this error which I think reveals a bit about why this limit exists: https://support.google.com/mail/answer/22839

    Message bounced due to sending limit

    In an effort to fight spam and prevent abuse, Google will temporarily disable your account if you send messages to more than 500 recipients or if you send a large number of undeliverable messages. If you use a POP or IMAP client (for example: Microsoft Outlook or Apple Mail), you may only send a message to 100 people at a time. Your account should be re-enabled within 24 hours.

    If you communicate with the same group of people on a regular basis, you might be interested in Google Groups.

    If you send a large number of undeliverable messages, we suggest verifying your contacts' email addresses. It's also important that everyone you are sending mail to is willing to receive it.

    Learn more about best practices for sending a large amount of mail through Gmail.