Пример #1
0
        private static void EmailsSend()
        {
            var emailSender = new Saritasa.Tools.Emails.SmtpClientEmailSender(new SmtpClient(), TimeSpan.FromSeconds(10));

            for (int i = 0; i < 2; i++)
            {
                new System.Threading.Thread(() =>
                {
                    emailSender.SendAsync(new MailMessage("*****@*****.**", "*****@*****.**", "test", "body"));
                    emailSender.SendAsync(new MailMessage("*****@*****.**", "*****@*****.**", "test2-" + i, "body"));
                }).Start();
            }
        }
 /// <summary>
 /// .ctor
 /// </summary>
 /// <param name="smtpClientInstancesCount">Max number of instances. 2 by default.</param>
 /// <param name="smtpClient">Smtp client to be used as reference object. If null default settings
 /// from configuration will be used.</param>
 public MultiSmtpClientEmailSender(int smtpClientInstancesCount = 2, SmtpClient smtpClient = null)
 {
     if (smtpClientInstancesCount <= 0)
     {
         throw new ArgumentOutOfRangeException(string.Format(Properties.Strings.ArgumentMustBeGreaterThan,
                                                             smtpClientInstancesCount, "zero"));
     }
     clientInstances = new SmtpClientEmailSender[smtpClientInstancesCount];
     for (int i = 0; i < smtpClientInstancesCount; i++)
     {
         var clonedSmtpClient = CloneSmtpClient(smtpClient);
         clientInstances[i] = new SmtpClientEmailSender(clonedSmtpClient);
         clientInstances[i].Client.ServicePoint.ConnectionLimit = smtpClientInstancesCount;
     }
 }