How to clear the email queue?

How to clear the email queue?

by Alan Tygel -
Number of replies: 6

Hi,

I've recently rescued an old Moodle instance, upgrading it from version 3.8 until the latest one. Everything went fine, thanks to the comprehensive documentation.

This instance stand for a long time without a working cronjob. Thus, users were created and welcome emails were not sent. After the server cron was fixed, it started trying to send emails, but the SMTP server was not configured. And now the logstore_standard_log table is exploding, because sending emails are failing to be send. It generates both \core\event\user_password_updated and email_failed errors.

However, these emails are meaningless now, because they refer to very old actions. Now I'm locked: I cannot fix the SMTP server, because I don't want the emails to be send.

How can I clear the old email queue so that I can fix the SMTP server and avoid sending meaningless emails?

best,

alan

Average of ratings: -
In reply to Alan Tygel

How to clear the email queue?

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
There are all kinds of flags you can set in the config.php. For example:
// When working with production data on test servers, no emails or other messages
// should ever be send to real users
// $CFG->noemailever = true; // NOT FOR PRODUCTION SERVERS!
//
// Divert all outgoing emails to this address to test and debug emailing features
// $CFG->divertallemailsto = 'root@localhost.local'; // NOT FOR PRODUCTION SERVERS

Reg. config-dist.php next to config.php.
Average of ratings: Useful (1)
In reply to Visvanath Ratnaweera

How to clear the email queue?

by Alan Tygel -

Thanks! Is not exactly what I was looking for, but looks a nice solution if I dont get to effectively clear the queue.

In reply to Alan Tygel

How to clear the email queue?

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
There are two queues involved:
1. Moodle's own queue, if the mail sending server does not respond
2. Queue in the mail sending server it the recipient mail servers do not respond.

Your mails are in 1). If you operate a mail sending server, like a local postfix agent, then you can release 1) by making the local mail sending server to accept mail but not to send then. Instead purge the queue. In postfix 'postsuper -d ALL' (from memory).
Average of ratings: Useful (2)
In reply to Alan Tygel

How to clear the email queue?

by Ken Task -
Picture of Particularly helpful Moodlers

In addition to Mr. V's suggestions:
Go to:  Site administration
Server
Tasks
Scheduled tasks

Turn off anything related to notifications. (turn back on after things settle down)

The 'que' is really in a moodle table.
truncate mdl_adhoc_task table.

And for future control/setup ...
install a localhost only postfix.
Create a user on the system called mdladmin - it has an inbox then.
Email address to use for the admin in moodle would be:
mdladmin@fqdnofmoodleserveritself

That mail will never leave the server and there are true mailques you can clear.  And you can check that mdladmin users inbox using alpine - a text based MTA.   Plus, there are actual mail server logs you can check for the 1st hop of an emall headed to your SMTP relay.   Postfix is set to relay any address not local to the SMTP relay.

Best, me thinks, to setup another user rather than attempting to use root ... it might already be getting notifications from your OS.

My 2 cents!

'SoS', Ken

Average of ratings: Useful (2)
In reply to Ken Task

How to clear the email queue?

by Alan Tygel -
Thanks for your answer!

I was able to stop the related task, and thus my log table is not exploding anymore.

Now I have to clear the queue. However, my moodle instance doesn't have this mdl_adhoc_task. I'm at 5.1.3. Any other suggestion?
In reply to Alan Tygel

How to clear the email queue?

by Ken Task -
Picture of Particularly helpful Moodlers

"my moodle instance doesn't have this mdl_adhoc_task"

Huh???!!!

Got command line access to you site?  Try this from mysql/mariadb  client:

mysql> show tables like '%adhoc%';

should show that table exists. (It NOT, you got troubles!!!)

+-----------------------------+
| Tables_in_m51test (%adhoc%) |
+-----------------------------+
| mdl_task_adhoc              |
+-----------------------------+

Also, from command line via shell to server:

cd /path/to/moodlecode/admin/cli/ [enter]

php checks.php -v

Everything there OK?

'SoS', Ken

Average of ratings: Useful (1)