title: Break apart email attachment if zip is too big to email
body: <blockquote>
  <p>So I can send up to 25MB in an email attachment. I am looking for away to check how big the file size is and if its too big break it apart and send in two emails. (Or if there is a better way to do it)?</p>
  <p>Here is where I am sending the email with the attachment:</p>
  </blockquote>
  <pre><code>public static void SendEmail(List&lt;string&gt; recipients, MemoryStream output, string from, string subject, string htmlMessage, bool isHtml = true)
      {
          var host = ConfigurationManager.AppSettings[&quot;emailHost&quot;];
          var emailFrom = ConfigurationManager.AppSettings[&quot;FromEmail&quot;];
          try
          {
              MailMessage mail = new MailMessage();
              mail.From = new MailAddress(from);
              
              foreach (var r in recipients)
              {
                  mail.To.Add(r);
              }
              
              mail.Subject = subject;
              mail.IsBodyHtml = isHtml;
              mail.Body = htmlMessage;
              //string result = System.Text.Encoding.UTF8.GetString(output.ToArray());
  
              SmtpClient SmtpServer = new SmtpClient(host);
              SmtpServer.Port = 25;
              
  
              Attachment myZip = new Attachment(output, &quot;ClientStatements.zip&quot;);
              mail.Attachments.Add(myZip);
              SmtpServer.Send(mail);
          }
          catch (Exception ex)
          {
             FMBUtilities.Logger.LogErrorToSql2012PrdAndEmailTeam(&quot;DBQueries&quot;, &quot;SendEmail&quot;, ex);
          }
      }
  </code></pre>
  <blockquote>
  <p>Here is where i am creating the zip file to send:</p>
  </blockquote>
  <pre><code>if (emails.ToString() != &quot;&quot;)
                  {
                      var allEmails = emails[0].Split(',');
  
                      foreach (var email in allEmails)
                      {
  
                          if (emailValid.IsMatch(email))
                          {
                              everyEmail.Add(email);
                          }
                          else
                          {
                              return Json(new { success = false, message = $&quot;* Not valid email address: {email}.\n\n * Please double check and try again.&quot; });
                          }
                      }
                          MemoryStream output = new MemoryStream();
  
                          List&lt;string&gt; distinctFiles = allPaths
                              .GroupBy(x =&gt; x.Split(new char[] { '\\' }).Last())
                              .Select(x =&gt; x.First())
                              .ToList();
                          using (ZipFile zip = new ZipFile())
                          {
                                
                              zip.AddFiles(distinctFiles, @&quot;\&quot;);
                              
                              zip.Save(output);
                              output.Position = 0;
                              
                              DBQueries.SendEmail(everyEmail, output, fromAddress, &quot;Client Statement Reports&quot;, &quot;Here are your requested Client Statements&quot;, true);
  
                          }
  </code></pre>
  <blockquote>
  <p>I have found some things about setting the file size in the web.config file and things of that sort but just dont know the best way to go about this.</p>
  </blockquote>