How to delete the queue of outgoing (notification) mails

How to delete the queue of outgoing (notification) mails

by Lexi K -
Number of replies: 10

Version: Moodle 3.5+ (Build: 20180614)

Hello,

we have a problem with our Moodle instance and it hasn't been running cronjobs for more than 30 days I think so I'd like to delete the queue of outgoing notification mails. If not everyone will get a lot of mails that have stacked up over the last 30+ days and the courses are already over.

I couldn't find anything about how to do this, only debugging problems or looking at the list of when jobs were last run etc.

Thanks for reading

Lexi

Average of ratings: -
In reply to Lexi K

Re: How to delete the queue of outgoing (notification) mails

by Ken Task -
Picture of Particularly helpful Moodlers

Moodle isn't a mail server.  It does 'package up' ... ie, builds information into EMail formats to be sent and attempts to send ... but it doesn't really have a 'que' of mail that hasn't been delivered for one reason or another.   That's the job of the mail server to which Moodle is pointed via SMTP or if one is NOT using an SMTP relay then it could be the local Exim/PostFix/Sendmail ques on the server itself.

So to clear mailques, one has to check the ques of whatever is setup to handle the mail.

Hope that helps in where to look!

'spirit of sharing', Ken


In reply to Ken Task

Re: How to delete the queue of outgoing (notification) mails

by Lexi K -

Hi Ken, thanks for your reply. So but since our conrjob seems to never get executed Moodle will never actually pass the information to the mail server, right? So where is that list? As I said I don't think it's possible for the server to store them because I think that's what the cronjob does that is never executed. BTW queues are written like that, strange eh?

In reply to Lexi K

Re: How to delete the queue of outgoing (notification) mails

by Ken Task -
Picture of Particularly helpful Moodlers

The main cron job actually consist of a series of 'scheduled task' in 3.5.   The task can be executed by themselves.

Go to: https://yoursite/admin/tool/task/scheduledtasks.php

Find related task  ... there is a 'run now' link.  You won't find one for 'clear mail ques' cause Moodle isn't a mail server! smile

There is one for "Check for updates \core\task\check_for_updates_task"

and one for

Forum mailings and maintenance jobs \mod_forum\task\cron_task

Those are both part of the main cron job but when running the task, limited to only that part/piece of the main cron job.

If linux, suggest having a ssh terminal window open where you can watch server logs in realtime.  I install a thing called multitail and then configure it to show me realtime logs ... access log, error logs of apache, messages log, and if you are running Exim/PostFix/Sendmail then their log file.

Or 'poor mans monitor' ... tail -f /var/log/maillog

'spirit of sharing', Ken


In reply to Ken Task

Re: How to delete the queue of outgoing (notification) mails

by Lexi K -

Yeah I am using GNU+Linux and SSH. Hmm but I don't want to have a look at logs. Moodle must have some way of collecting or marking which forum posts trigger mails because it can only tell the mail server that mails should be send when the cronjob gets run, no? I know it's not a mail server, but how would it tell the mail server what mails need to be send if it doesn't have a list somewhere? Moodle can't send these directly itself afaik, this is what the cronjob is for, right?

In reply to Lexi K

Re: How to delete the queue of outgoing (notification) mails

by Ken Task -
Picture of Particularly helpful Moodlers

What logging moodle does can be found in 'reports' which is queying mdl_logstore_standard_log table.

Go look at that.   Think that's the only logs you got in the moodle interface that's related to forum postings/mail ... but no mailque.  There are 9 tables for forums.  If one did explain on all 9 of them, one at a time, one might see a column sorta related to what you are asking, I think.

"but I don't want to have a look at logs" ... Errr, uhhh ... sorry, but once moodle packages up whatever it's supposed to send, a cron job/task will attempt to send as many and as soon as it can - that's handed over to the mail server and it's que.

Other wise, 'bounces' (postmaster notifications which are in RFC guidelines for administering a mail server) don't come back to Moodle code they go back to the sending ***mail server*** ... and, I for one, would NOT want Moodle to attempt to handle that!

Do you have any tool to browse Moodle tables?  

'spirit of  sharing', Ken


In reply to Lexi K

Re: How to delete the queue of outgoing (notification) mails

by Ken Task -
Picture of Particularly helpful Moodlers

Forums could be forced subscribed.

Find all the forums via overview of plugins.   Visit each forum and check settings.

Even changing config ... forums have already sent the mail ... Elvis left the building.

I had this happen about a week or so ago with a newbie Moodle admin ... thankful that I had Postfix in front of any other smarthost (smtp relay) cause I let Moodle do it's thing and manually cleared the mailques as messages came in thus preventing the moodle server from getting blacklisted god knows where.  And didn't mess with config of forums .... 125 of them ... nor the related tables.   Did have a long talk with the newbie Moodle admin though.   Not his fault ... he didn't know that 8000+ users were subscribed to a hidden forum that had never been used by former Moodle Admin.

Not ideal ... a pain in the arse ... but ....

'spirit of sharing', Ken


In reply to Ken Task

Re: How to delete the queue of outgoing (notification) mails

by Lexi K -

Hey Ken. Thanks for sticking with me. Moodle has to keep track of the forum notifications somewhere because if not how would it be able to tell the mail server which mails it would need to send out when the cronjob runs?

I want to find that place and delete the forum notifications so that no one gets spammed with old notifications that are not needed anymore.

That's why I think logs won't cut it -- afaik logs only document what has happened, they do not store what is supposed to happen later, right?

Modifying the forum configs for subscriptions may cut it. That's a good idea. However I would need to find out if it really will work.

I can be sure that no mails were already created by the mail server because the cronjob for Moodle to tell the mail server to create mails has not been run for a long time/ever.

"sorry, but once moodle packages up whatever it's supposed to send, a cron job/task will attempt to send as many and as soon as it can - that's handed over to the mail server and it's que."

Yeah, I know the cronjob has not been run so how do I find that package that Moodle has packaged up of what it's supposed to send? I want to delete exactly that or change it so nothing will get send. Probably Moodle checks in the database whether a forum post has been sent to the subscribed users. So I would need to find that information and overwrite it manually to "yes the mails have already been sent" or "there are no subscribers."

I am looking at the database with mysql terminal tool and try to find where Moodle keeps track of what notifications need to be send when the cronjob gets run. Is there an official documentation about what table does what and what column is for what purpose?

I have more ideas how to solve the problem now so thank you again Ken!

In reply to Lexi K

Re: How to delete the queue of outgoing (notification) mails

by Ken Task -
Picture of Particularly helpful Moodlers

There's human 'logic' (maybe that's you and I) ... then there's 'computer logic' ... then there's 'program logic' ... etc.  Are they all the same? ... ie, do they all 'think alike'?   Not really a  question for response ... just a thought.

Anyhoo ... one of the 8 tables

mdl_forum
mdl_forum_digests
mdl_forum_discussions
mdl_forum_posts
mdl_forum_queue
mdl_forum_read
mdl_forum_subscriptions
mdl_forum_track_prefs

See what's in them on your system.   None of the 'clients' I help use forums.

In mdl_forum_posts.  There's a 'mailed' column and a 'mailnow' column ... if user opts to 'mailnow' in things like forums, etc., Elvis tries the leave the building right away - which, I think, would mean data is packaged up and control handed off to mail systems.

There is no task/part of cron job that attempts cancelling or clearing a mailque ... locally or on an SMTP server somewhere.   Deleting the row??? Might confuse other related tables but, hopefully, moodle would recover and one would not be stuck with looking at an error every day.

And depending upon the number of persons to get the message, that could be really quickly accomplished, or, in the case of 8000 users forced subscribed that could tax a server, do all sorts of different things related to mail systems.

Then there are user preferences for handling mail or messages.

Could have simply said ... dunno ... but, did dunno with an explanation ... maybe it will lead you somewhere.

Maybe if we made a plea to the real Moodle Guru's one would jump in here and clear the confusion. smile

*Calling ALL Moodle Guru's!!!  Got a minute?  HELP Lexi K out!*

'spirit of sharing', Ken


In reply to Ken Task

Re: How to delete the queue of outgoing (notification) mails

by Lexi K -

Hey Ken, I just risked it and turned off notification subscriptions. There were only two relevant forums anyway. It seems to have worked, although I can't tell for sure yet. Will post again if I know more so people with the same problem in the future know whether turning off notification subscriptions is a possible solution. Thanks again

In reply to Lexi K

Re: How to delete the queue of outgoing (notification) mails

by Ken Task -
Picture of Particularly helpful Moodlers

Is your cron now running ok?   That's a must with Moodle these days!

'spirit of sharing', Ken