private void WorkerThreadFunc()
        {
            if (settings != null && true)
            {
                dbHelper helper = new dbHelper();

                string smtpEmailAddress = settings["SMTPUserName"];
                string smtpPassword = settings["SMTPPassword"];
                // string fromEmail = settings["FromEmail"];
                // string fromDisplayName = settings["FromDisplayName"];
                string smtpClientHost = settings["SMTPHostName"];
                int smtoClientPort = int.Parse(settings["SMTPHostPort"]);
                bool enableSsl = bool.Parse(settings["EnableSSL"]);
                bool useDefaultCredentials = bool.Parse(settings["UseDefaultCredentials"]);
                int emailForBulk = 50, reTryTime = 5;
                int.TryParse(settings["EmailForBulk"], out emailForBulk);
                int.TryParse(settings["ReTryTime"], out reTryTime);
                var databundle = helper.GetmailBulk(DateTime.Now, emailForBulk);

                var notsendbundle = helper.GetFailedBulk(reTryTime);
                if (databundle != null)
                {
                    databundle.AddRange(notsendbundle);
                }
                else
                    databundle = notsendbundle;
                if (databundle != null)
                {
                    helper.SetSettingFromKey("LastRunTime", DateTime.Now.ToString());
                    Parallel.ForEach(databundle, item =>
                    {
                        string newGuid = Guid.NewGuid().ToString();
                        var mail = new mailDetails() { guid = newGuid, mail = item };
                        collection.Add(mail);

                        sendEmail(mail, smtpEmailAddress, smtpPassword, smtpClientHost, smtoClientPort, enableSsl, useDefaultCredentials);
                    });
                }
            }

            current_thread_count--;
            if (!emailerTimer.Enabled)
                emailerTimer.Start();
        }
        void updateDetails(mailDetails mail, bool Cancelled, Exception Error)
        {
            try
            {

                string error = null;
                var updateData = mail.mail;
                int int_failed_count = 0;
                if (updateData.int_failed_count != null)
                    int_failed_count = updateData.int_failed_count.Value;
                int int_satues = 0;
                if (!Cancelled && Error == null)
                {
                    updateData.dt_send_date = DateTime.Now;

                    int_satues = 255;
                }
                else
                {
                    int_satues = -1;

                    logHelper.LogException(Error, main_path);
                    if (Error != null)
                    {
                        if (Error.InnerException != null)
                            error = Error.InnerException.Message;
                        else
                            error = Error.Message;
                    }
                    int_failed_count++;
                }

                updateData.str_error = error;
                updateData.int_status = int_satues;
                updateData.int_failed_count = int_failed_count;

                dbHelper helper = new dbHelper();
                if (helper.UpdateData(updateData))
                    collection.Remove(mail);
            }

            catch (Exception er)
            {
                logHelper.LogException(er, main_path);

            }
        }
        void FillSettings()
        {
            dbHelper helper = new dbHelper();
            var EmailSendInterval = helper.GetSettingFromKey("EmailSendInterval", "10");
            var EmailForBulk = helper.GetSettingFromKey("EmailForBulk", "50");
            var SMTPUserName = helper.GetSettingFromKey("SMTPUserName", "");
            var SMTPPassword = helper.GetSettingFromKey("SMTPPassword", "");
            var SMTPHostName = helper.GetSettingFromKey("SMTPHostName", "");
            var SMTPHostPort = helper.GetSettingFromKey("SMTPHostPort", "");
            var EnableSSL = helper.GetSettingFromKey("EnableSSL", "true");
            var LastRunTime = helper.GetSettingFromKey("LastRunTime", "");
            var ReTryTime = helper.GetSettingFromKey("ReTryTime", "5");
            var UseDefaultCredentials = helper.GetSettingFromKey("UseDefaultCredentials", "false");
            var ThreadCount = helper.GetSettingFromKey("ThreadCount", "1");
            if (ReTryTime != "" && EmailSendInterval != "" && EmailForBulk != "" && SMTPUserName != "" && SMTPPassword != "" && SMTPHostName != ""
                && SMTPHostPort != "" && EnableSSL != "" && UseDefaultCredentials != "" && ThreadCount != "")
            {
                settings = new Dictionary<string, string>();
                settings.Add("EmailSendInterval", EmailSendInterval);
                settings.Add("EmailForBulk", EmailForBulk);
                settings.Add("SMTPUserName", SMTPUserName);
                settings.Add("SMTPPassword", SMTPPassword);
                settings.Add("SMTPHostName", SMTPHostName);
                settings.Add("SMTPHostPort", SMTPHostPort);
                settings.Add("EnableSSL", EnableSSL);
                settings.Add("LastRunTime", LastRunTime);
                settings.Add("ReTryTime", ReTryTime);
                settings.Add("ThreadCount", ThreadCount);
                settings.Add("UseDefaultCredentials", UseDefaultCredentials);

            }
            else { logHelper.LogException(new Exception("Settings are invalid"), main_path); }
        }
Beispiel #4
0
 public void FillStatus()
 {
     dbHelper helper = new dbHelper();
     summary = helper.GetEmailSummary();
 }
Beispiel #5
0
 public void FillSettings()
 {
     dbHelper helper = new dbHelper();
     settings = helper.GetAllSetting();
 }
Beispiel #6
0
 public void FillPenndingEmails()
 {
     dbHelper helper = new dbHelper();
     penddingEmails = helper.GetEmailsByStatus(0,DateTime.Now);
 }
Beispiel #7
-56
        internal void Process()
        {
            dbHelper helper = new dbHelper();
            helper.UpdateMissedData();
            FillSettings();
            if (settings != null)
            {
                double timerInterval = 10;
                double.TryParse(settings["EmailSendInterval"], out timerInterval);
                int.TryParse(settings["ThreadCount"], out thread_count);

                if (timerInterval == 0)
                    timerInterval = 0.1;
                collection = new List<mailDetails>();

                emailerTimer = new System.Timers.Timer();
                emailerTimer.Elapsed += new System.Timers.ElapsedEventHandler(GetMail);

                emailerTimer.Interval = 60000 * timerInterval;
                emailerTimer.Enabled = true;
                emailerTimer.AutoReset = true;
                emailerTimer.Start();

            }
        }