title: Send email using smtp client in c#
body: <p>the following code gets recipients email, email subject and email body from a table and creates the emails and sends them to a pickup directory. there is a db connection class that I did not include here, but I invoke it in the code below. 
  The code below runs fine however I am wondering if it could be improved to run faster considering It will be used to send 10000 plus emails.</p>
  
  <p>Thanks in advance for any help.</p>
  
  <pre><code>using System;
  using System.Collections;
  using System.Collections.Generic;
  using System.Text;
  using System.Net;
  using System.Net.Mail;
  using System.Data;
  using System.Data.SqlClient;
  using System.IO;
  
  namespace SendEmails
  {
  class SendEmail
  {
      private class EmailsList
      {
          private class listData
          {
              public string email;
              public string email_header;
              public string email_body;
              public string email_guid;
          }
          public void data()
          {
              SqlDataReader sqlData;
              ArrayList Emaillist = new ArrayList();
              sqlData = new SqlCommand("SELECT email, email_header, email_body, email_guid FROM dbo.vw_emails ", con.openconnection()).ExecuteReader();
              // loop through the emails table and load arraylist
              while (sqlData.Read())
              {
                  listData itemData = new listData();
                  itemData.email = sqlData[0].ToString();
                  itemData.email_header = sqlData[1].ToString();
                  itemData.email_body = sqlData[2].ToString();
                  itemData.email_guid = sqlData[3].ToString();
                  Emaillist.Add(itemData);                
              }               
              sqlData.Close();
              con.closeconnection
  
              foreach (listData itemData in Eamillist)
              {
                  //SEND EMAIL *****************************/
                  spSendMail(itemData.email, itemData.email_header, "me@yahoo.com", itemData.email_body, itemData.email_guid);
                  //DO THE UPDATE *********************/
                  SqlCommand cmd = new SqlCommand("up_emailLog", con.openconncetion());
                  cmd.CommandType = CommandType.StoredProcedure;
                  cmd.Parameters.AddWithValue("@email_GUID", itemData.email_guid);
                  cmd.CommandTimeout = 0;
                  cmd.ExecuteNonQuery();
                  con.CloseConnection();
  
              }
          }
      }
  
      static void Main(string[] args)
      {
          try
          {
             EmailsList sEmails = new EmailsList();
              sEmails.data();                    
          }
          catch (Exception ex)
          {
              SqlCommand cmd = new SqlCommand("INSERT INTO [dbo.Err_Log](exception, insdt) VALUES('" + ex.Message.ToString() + "','" +  "','"+ DateTime.Now + "')", Con.OpenConnection());
              cmd.ExecuteNonQuery();
              con.CloseConnection();                 
          }
      }
      // Send Email Method
      public static void spSendMail(string recipients, string subject, string from, string body, string email_guid)
      {
          try
          {
              using (MailMessage mailMessage = new MailMessage(from, recipients))
              {
                      mailMessage.Subject = subject;
                      mailMessage.Body = body;
                      mailMessage.IsBodyHtml = true;
                      SmtpClient smtpClient = new SmtpClient("xxxxxx.xxxx.zo");
                      smtpClient.UseDefaultCredentials = true;
                      smtpClient.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
                      smtpClient.PickupDirectoryLocation = "\\\\exchange_server\\pickup";
                      //Create eml file and send it to pickup directory
                      smtpClient.Send(mailMessage);                               
              }
          }
          catch (Exception ex)
          {
              SqlCommand cmd = new SqlCommand("INSERT INTO [dbo.Err_Log](exception, communication, insdt) VALUES('" + ex.Message.ToString() +"','" + recipients.ToString() + "','" + DateTime.Now + "')", con.OpenConnection());
              cmd.CommandTimeout = 0;
              cmd.ExecuteNonQuery();
              Con.CloseConnection();
          }
      }
  } 
  </code></pre>
  
  <p>}</p>