public void StartJob(string jobId, SmtpConfig cfg)
        {
            _smtpCfg = cfg;
            _mailer  = new SmartMailer();
            _mailer.Configure(_smtpCfg);
            if (_job != null)
            {
                StopJob();
            }

            _mailToSend = _appSvc.GetMailCorrente();
            var timeout = DateTime.Now.AddSeconds(15);

            while (_timer != null && _timer.Enabled)
            {
                if (timeout <= DateTime.Now)
                {
                    break;
                }
                Thread.Sleep(200);
            }

            _timer?.Dispose();
            _timer = null;

            try
            {
                _job = new JobDescriptor()
                {
                    JobId = jobId, IsRunning = true
                };
                _timer          = new Timer(DELTA);
                _timer.Elapsed += (sender, e) => OnTimedEvent(sender, e, this);
                _timer.Start();
                State = ESchedulerState.Running;
            }
            catch (Exception exc)
            {
                State = ESchedulerState.Stopped;
                _timer?.Dispose();
                _timer = null;
                throw;
            }
        }
Exemple #2
0
        private void btnTestMail_Click(object sender, EventArgs e)
        {
            var dlg = new InputBox();
            var res = dlg.Execute(this, "Immetti un destinatario", "Test send mail", true);

            if (res)
            {
                CtrlToModel();
                var mailer = new SmartMailer();
                mailer.Configure(_smtpCfg);
                try
                {
                    mailer.SendEmail(dlg.InputText, "Nome dest", "Mail di test",
                                     "Questo è un <b>esempio</b> di corpo mail html.</br>Inviato con BulkMailSender application.",
                                     "Questo è un esempio di corpo mail text. Inviato con BulkMailSender application.");
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message, "Errore", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }