mirror of
https://github.com/itflow-org/itflow
synced 2026-11-24 21:37:28 +00:00
Mail queue stage 3: show failed and stuck mail on the Settings overview and Mail tile, a mail queue summary on the Mail Tests tab and a failed-this-week count on the Mail Queue menu item, add Mail Queue to the Ctrl K search for admins, and say where to watch a test email go
This commit is contained in:
@@ -1035,6 +1035,7 @@ If you are coming from 26.08 or earlier, the database update still has to be run
|
||||
- Retry now starts an email over - a full set of tries, at the next run - for a failed or cancelled one. Cancel is its own status now, rather than Failed. Retry now, Cancel and Delete are on each email's menu and in Bulk Action, done only to the ones they can be, saying how many and why not the rest.
|
||||
- Why an email failed is kept with it - the mail server's own answer, an address that isn't one, no from address, a domain with no mail server - and shown under its status and searched. Cancelling keeps who cancelled it. The alert for a failed email says why and when it is tried again, and when ITFlow gives up after the last try there is an alert for that too, each opening the Mail Queue on its tab.
|
||||
- Opening an email shows where it stands and why, who it is to and from, when it was queued, how many tries it has had, when it was sent or last failed, its attachments and calendar file - and the email itself as it will arrive, rather than stripped of its layout. A sent one says what it said was cleared on sending, and why. Retry now, Cancel and Delete are in the window too.
|
||||
- Without opening it: the Settings overview says when email failed to send in the last day, and when the queue isn't moving, and the Mail tile how many failed this week; the Mail Queue menu item carries the same count; Mail's Tests tab shows when mail was last sent and what is waiting, retrying or failed. The Mail Queue is in the search window (Ctrl K) for admins, and the test email says where to watch it go.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
@@ -1754,6 +1755,7 @@ If you are coming from 26.08 or earlier, the database update still has to be run
|
||||
- Settings: Notifications, Security, Client portal, Single sign-on (`admin/identity_providers.php`), Mail and Logs use the frame. `settingsSearch($query, $limit)` scores settings as Find a setting does, leaving out pages for a module that is off; `agent/ajax.php?global_search` returns them as `settings` for admins and `js/global_search.js` shows them under Settings. Single sign-on's fields are renamed to their columns (`config_azure_client_id`, `config_azure_client_secret`). A field marked `quiet` in `settingsFields()` is logged as changed without its value (the login key). The Logs handler is unchanged; Mail's handlers too.
|
||||
- Mail Queue: new `functions/mail_queue.php` - `MAIL_QUEUE_TRIES` (4), `MAIL_QUEUE_RETRY_MINUTES` (30) and `MAIL_QUEUE_KEEP_DAYS` (90), which `cron/mail_queue.php`'s retry pass and the nightly clean-up now use too; `mailQueueTabs()`, `mailQueueState($row)`, `mailQueueCan($row, $action)`, `mailQueueAct($action, $ids)` and `mailQueueHealth()`. `email_status` 4 is Cancelled - never selected by the worker. Retry now sets status 0, no attempts and no failure time. Handlers: `retry_mail`, `cancel_mail`, `delete_mail` (GET with the CSRF token) and `bulk_retry_emails`, `bulk_cancel_emails`, `bulk_delete_emails`; `send_failed_mail` still works. The worker sets `email_failed_at` on the bad sender, bad recipient and no-MX paths.
|
||||
- Mail Queue: database 3.3.7 adds `email_queue.email_error` varchar(500) - why it last failed, or "Cancelled by ..."; cleared when sent or retried. The worker writes it on every failure path, through `mailQueueErrorSql()`, which leaves it out until the update has run, so an install between updating its files and its database still sends; `mailQueueErrorColumn()` does the same for reads. The retry pass's bad-recipient path now sets `email_failed_at`, so its backoff counts from that try. An alert (`appNotify`) when the retry pass gives up. The email's window shows the queued HTML in an iframe `srcdoc` with `sandbox="allow-popups allow-popups-to-escape-sandbox"` (no scripts, no same origin) and a `script-src 'none'` policy, instead of HTMLPurifier in the page.
|
||||
- Mail Queue: `mailQueueSummary()` - waiting, retrying, failed in the last day and week, and the last sent - read once a request, for the Settings overview (attention items and the Mail tile), Mail's Tests tab and the admin menu's count (`admin/includes/side_nav.php`). `globalSearchPages()` has Mail Queue for admins.
|
||||
- `js/app.js`: the four `tinymce.init()` calls go through `itflowTinyMce`, which does nothing where TinyMCE isn't loaded.
|
||||
|
||||
### Library Updates
|
||||
|
||||
@@ -180,7 +180,13 @@
|
||||
<li class="nav-item">
|
||||
<a href="/admin/mail_queue.php" class="nav-link <?= (basename($_SERVER['PHP_SELF']) == 'mail_queue.php' ? 'active' : '') ?>">
|
||||
<i class="nav-icon fas fa-inbox"></i>
|
||||
<p>Mail Queue</p>
|
||||
<p>
|
||||
Mail Queue
|
||||
<?php $nav_mail_failed = mailQueueSummary()['failed_week']; ?>
|
||||
<?php if ($nav_mail_failed) { ?>
|
||||
<span class="right badge text-bg-danger" data-bs-toggle="tooltip" title="Failed to send in the last week" data-nav-mail-failed><?= $nav_mail_failed ?></span>
|
||||
<?php } ?>
|
||||
</p>
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
|
||||
@@ -254,7 +254,7 @@ if (isset($_POST['test_email_smtp'])) {
|
||||
$sent = emailTestSend($to, $mailbox);
|
||||
|
||||
if ($sent) {
|
||||
flashAlert("Test email queued! Check <strong>Admin > Mail queue</strong>");
|
||||
flashAlert('Test email queued - it goes within a minute. Watch it go in <strong>Maintenance > Mail Queue</strong>');
|
||||
} else {
|
||||
flashAlert(escapeHtml($to) . " isn't an email address - nothing was queued", 'error');
|
||||
}
|
||||
|
||||
@@ -41,7 +41,8 @@ $summaries = [
|
||||
'project' => 'Next ' . escapeHtml($config_project_prefix . $config_project_next_number),
|
||||
'quote' => 'Next ' . escapeHtml($config_quote_prefix . $config_quote_next_number),
|
||||
'invoice' => 'Next ' . escapeHtml($config_invoice_prefix . $config_invoice_next_number) . ' · reminders ' . $on_off($config_send_invoice_reminders) . ' · late fees ' . $on_off($config_invoice_late_fee_enable),
|
||||
'mail' => 'Sending ' . ($config_smtp_provider ? 'on' : '<span class="text-danger-emphasis">off</span>') . ' · receiving ' . $on_off($config_imap_provider),
|
||||
'mail' => 'Sending ' . ($config_smtp_provider ? 'on' : '<span class="text-danger-emphasis">off</span>') . ' · receiving ' . $on_off($config_imap_provider)
|
||||
. (mailQueueSummary()['failed_week'] ? ' · <span class="text-danger-emphasis">' . mailQueueSummary()['failed_week'] . ' failed this week</span>' : ''),
|
||||
'notification' => 'Domain alerts ' . $on_off($config_enable_alert_domain_expire) . ' · ticket emails to clients ' . $on_off($config_ticket_client_general_notifications),
|
||||
'security' => 'Login key ' . $on_off($config_login_key_required) . ' · devices remembered ' . $days($config_login_remember_me_expire),
|
||||
'client_portal' => 'Two-step sign-in ' . ($config_client_portal_require_mfa ? 'required' : 'optional'),
|
||||
@@ -62,6 +63,16 @@ if ($config_ticket_email_parse && $config_module_enable_ticketing && empty($conf
|
||||
if ($config_login_key_required && trim((string) $config_login_key_secret) === '') {
|
||||
$attention[] = ['warning', 'fa-key', 'A login key is required, but there isn\'t one', 'The sign-in page asks for a key nobody has been given.', 'settings_security.php#setting=config_login_key_secret', 'Set the key'];
|
||||
}
|
||||
// The mail queue - email given up on, or a queue that isn't moving (sending off is said above)
|
||||
$mail_queue = mailQueueSummary();
|
||||
if ($mail_queue['failed_day']) {
|
||||
$attention[] = ['danger', 'fa-envelope-open-text', $mail_queue['failed_day'] . ' email' . ($mail_queue['failed_day'] === 1 ? '' : 's') . ' failed to send',
|
||||
'In the last day - ITFlow tried ' . MAIL_QUEUE_TRIES . ' times and gave up. The Mail Queue says why, and can try again.', 'mail_queue.php?show=failed', 'See why'];
|
||||
}
|
||||
$mail_queue_health = mailQueueHealth();
|
||||
if (!empty($config_smtp_provider) && in_array($mail_queue_health['key'], ['cron_off', 'cron_stopped', 'job_off', 'slow'], true)) {
|
||||
$attention[] = [$mail_queue_health['level'], 'fa-inbox', $mail_queue_health['title'], $mail_queue_health['text'], 'mail_queue.php', 'Mail Queue'];
|
||||
}
|
||||
if (trim((string) $config_timezone) === '') {
|
||||
$attention[] = ['warning', 'fa-clock', 'No timezone', 'Dates and times are in the server\'s timezone until one is picked.', 'settings_localization.php#setting=config_timezone', 'Pick one'];
|
||||
}
|
||||
|
||||
@@ -367,6 +367,19 @@ $imap_ready = $imap_standard_ready || $imap_oauth_ready;
|
||||
<!-- ============================ TESTS ============================ -->
|
||||
<div class="tab-pane fade <?php if ($active_tab === 'tests') { echo 'show active'; } ?>" id="tab-tests" role="tabpanel">
|
||||
|
||||
<?php $mail_queue = mailQueueSummary(); ?>
|
||||
<div class="d-flex flex-wrap align-items-center gap-2 border rounded p-3 mb-4" data-mail-queue-summary>
|
||||
<i class="fas fa-fw fa-inbox text-body-secondary"></i>
|
||||
<span class="me-auto">
|
||||
<strong>Mail Queue</strong>
|
||||
<span class="text-body-secondary">- <?= $mail_queue['last_sent'] ? 'last sent ' . escapeHtml(timeAgo($mail_queue['last_sent'])) : 'nothing sent yet' ?></span>
|
||||
<?php if ($mail_queue['waiting']) { ?><span class="badge text-bg-primary ms-1"><?= $mail_queue['waiting'] ?> waiting</span><?php } ?>
|
||||
<?php if ($mail_queue['retrying']) { ?><span class="badge text-bg-warning ms-1"><?= $mail_queue['retrying'] ?> retrying</span><?php } ?>
|
||||
<?php if ($mail_queue['failed_day']) { ?><span class="badge text-bg-danger ms-1"><?= $mail_queue['failed_day'] ?> failed in the last day</span><?php } ?>
|
||||
</span>
|
||||
<a class="btn btn-sm btn-outline-secondary" href="mail_queue.php<?= $mail_queue['failed_day'] ? '?show=failed' : '' ?>">Open the Mail Queue</a>
|
||||
</div>
|
||||
|
||||
<?php if (!$send_ready && !$imap_ready && !$oauth_has_required_fields) { ?>
|
||||
<div class="alert alert-secondary mb-0">
|
||||
<i class="fas fa-fw fa-info-circle me-2"></i>Finish configuring Sending, Receiving, or OAuth (plus at least one From address) to unlock the tests.
|
||||
|
||||
@@ -241,3 +241,26 @@ function mailQueueErrorSql($error) {
|
||||
function mailQueueErrorColumn() {
|
||||
return mailQueueHasError() ? 'email_error' : 'NULL AS email_error';
|
||||
}
|
||||
|
||||
/*
|
||||
* The mail queue at a glance, for the pages that point to it - how many are
|
||||
* waiting (due now), retrying, and given up on in the last day and the last
|
||||
* week, and when one was last sent. Read once a request.
|
||||
*/
|
||||
function mailQueueSummary() {
|
||||
global $mysqli;
|
||||
static $summary = null;
|
||||
if ($summary !== null) {
|
||||
return $summary;
|
||||
}
|
||||
$tries = MAIL_QUEUE_TRIES;
|
||||
$row = mysqli_fetch_row(mysqli_query($mysqli, "SELECT
|
||||
COALESCE(SUM(email_status = 0 AND email_queued_at <= NOW()), 0),
|
||||
COALESCE(SUM(email_status = 2 AND email_attempts < $tries), 0),
|
||||
COALESCE(SUM(email_status = 2 AND email_attempts >= $tries AND email_failed_at >= NOW() - INTERVAL 1 DAY), 0),
|
||||
COALESCE(SUM(email_status = 2 AND email_attempts >= $tries AND email_failed_at >= NOW() - INTERVAL 7 DAY), 0),
|
||||
MAX(CASE WHEN email_status = 3 THEN email_sent_at END)
|
||||
FROM email_queue WHERE email_queued_at >= NOW() - INTERVAL " . MAIL_QUEUE_KEEP_DAYS . " DAY"));
|
||||
$summary = ['waiting' => intval($row[0] ?? 0), 'retrying' => intval($row[1] ?? 0), 'failed_day' => intval($row[2] ?? 0), 'failed_week' => intval($row[3] ?? 0), 'last_sent' => $row[4] ?? null];
|
||||
return $summary;
|
||||
}
|
||||
|
||||
@@ -906,6 +906,7 @@ function globalSearchPages($raw_query) {
|
||||
['Transfers', '/agent/transactions.php?show=transfers', $financial && $accounting],
|
||||
['Reports', '/agent/reports/', lookupUserPermission('module_reporting') >= 1],
|
||||
['Administration', '/admin/', (bool) $session_is_admin],
|
||||
['Mail Queue', '/admin/mail_queue.php', (bool) $session_is_admin],
|
||||
['My Account', '/agent/user/user_details.php', true],
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user