public async Task Run(TaskExecutionContext ctx, CancellationToken cancelToken = default)
        {
            int pageIndex = 0;
            while (true)
            {
                var queuedEmails = await _db.QueuedEmails
                    .Where(x => x.SentTries < 3 && x.SendManually == false)
                    .ApplyTimeFilter(null, null, true)
                    .ApplySorting(true)
                    .Include(x => x.Attachments)
                    .ToPagedList(pageIndex, 1000)
                    .LoadAsync();

                await _queuedEmailService.SendMailsAsync(queuedEmails, cancelToken);

                if (!queuedEmails.HasNextPage || cancelToken.IsCancellationRequested)
                    break;

                pageIndex++;
            }
        }
        public async Task <IActionResult> SendNow(QueuedEmailModel queuedEmailModel)
        {
            var queuedEmail = await _db.QueuedEmails.FindByIdAsync(queuedEmailModel.Id, false);

            if (queuedEmail == null)
            {
                return(RedirectToAction(nameof(List)));
            }

            var result = await _queuedEmailService.SendMailsAsync(new List <QueuedEmail> {
                queuedEmail
            });

            if (result)
            {
                NotifySuccess(T("Admin.Common.TaskSuccessfullyProcessed"));
            }
            else
            {
                NotifyError(T("Common.Error.SendMail"));
            }

            return(RedirectToAction(nameof(Edit), new { id = queuedEmail.Id }));
        }