Receive notifications on forum posts

Receive notifications on forum posts

by Jose M. -
Number of replies: 31
How can I get notified when a user posts a message in a forum? I have created a test course with some test users and I can not receive notifications when a user writes a message even though the notification settings in both the course and the user are set to receive emails. 
The cron job is already working. 
Average of ratings: -
In reply to Jose M.

Re: Receive notifications on forum posts

by Ken Task -
Picture of Particularly helpful Moodlers
Cron consist of jobs/task, one of which is
Forum mailings and maintenance jobs \mod_forum\task\cron_task
If you have the path to php-cli set in PATHS configuration of Moodle,
access the task list:
Site Admin -> Server -> Task -> Scheduled task
and then looking for the Forum mailings and maintained job you will see
a 'run now' link in the "last run" column.

Clicking 'run now' will show a warning ... click the Run Now button ...
and what follows is just that job ... no other jobs.

Since that job could contain many messages or a backlog be prepared for it
to run a long time.   Let it finish.

If it errors, copy the errors seen, come back here and share what it said.

'SoS', Ken

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

Re: Receive notifications on forum posts

by Jose M. -
Hi Ken,
I see the task '\message_email\task\send_email_task' in the list, it runs every 5 minutes as I can check in the log, but I can not see the 'run now' button, my moodle version is 4.1.5+.
All tests were done yesterday and the last forum message was written at 14:25h, at 18:00h I received an email informing me of the unread message in the forum, so maybe the problem is in the email account but if I manage to run the job manually I could identify the error if it exists.
In reply to Jose M.

Re: Receive notifications on forum posts

by Ken Task -
Picture of Particularly helpful Moodlers
The 'run now' link will only show IF you have set the path to php-cli in PATHS config of the site.

You could also see the error in error logs of your server.

Do you have an SMTP relay setup?   If not, your server is trying to use the built in PHPMailer and there are many mail servers that would reject messages coming from a server that didn't have MX, SPF, DKIM, etc. records in DNS.

Just one posting in a forum that goes to multiple users regardless of their email addresses could trigger your server getting blacklisted in one of those blackhole services offered on the net.    So it's a good idea if you are using forums, to setup an SMTP relay.

'SoS', Ken

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

Re: Receive notifications on forum posts

by Jose M. -
Hi Ken,

I have enabled the path to php-cli and I manage to run the job correctly, no errors. So the problem might be in what you said, the smtp server, because I have only added the email account provided by IT so that means the server is using PHPMailer. I need to talk to IT and check the smtp relay solution.

EDIT: If I test the outgoing email, it works and the message arrives instantly. 
In reply to Jose M.

Re: Receive notifications on forum posts

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
> If I test the outgoing email, it works and the message arrives instantly.

Then the IT has done its job. There must be something wrong in Moodle setup. The sure method of checking is to initiate a mail notification, like messaging somebody, and watch the SMTP server logs in real-time. That is what you've entered in the Moodle's Outgoing mail configuration. If the IT gave you that thing, then may be they only have access to the logs.
Average of ratings: Useful (1)
In reply to Visvanath Ratnaweera

Re: Receive notifications on forum posts

by Jose M. -
Hi Visvanath,

Messaging somebody also works and, like the outgoing test, the message arrives at the destination instantly.
In reply to Jose M.

Re: Receive notifications on forum posts

by François Lizotte -
Hi,
You say:
"at 18:00h I received an email informing me of the unread message in the forum"

It sounds like you are set up to receive a daily digest. Look at your own forum preferences:



Average of ratings: Useful (1)
In reply to François Lizotte

Re: Receive notifications on forum posts

by Jose M. -
Hi François,

Discarded, the selected option is an email at every forum message.
In reply to Jose M.

Re: Receive notifications on forum posts

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
Then very likely a user error on Moodle. Like the recipient is not subscribed to the forum, changed the e-mail settings in his profile, especially mail digest, etc. This is the case where the smtp server will deliver critical information: Whether Moodle tries to send a mail at all!
Average of ratings: Useful (1)
In reply to Visvanath Ratnaweera

Re: Receive notifications on forum posts

by Jose M. -
Hi Visvanath,

The user's settings are checked in order to receive forum notifications and an email at every post, besides, the user is displayed in forum suscribers, is that what you refered to?
In reply to Jose M.

Re: Receive notifications on forum posts

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
Yes, those are the things I meant by "user error". Since you've eliminated all that, the chances of finding the culprit by speculation sank. You need to change the strategy to a targeted approach - which is by reading the log file of the SMTP server.
Average of ratings: Useful (2)
In reply to Jose M.

Re: Receive notifications on forum posts

by Ken Task -
Picture of Particularly helpful Moodlers
The real 'acid test' is a forum that has mutliple users forced subscribed and someone posting in that forum.

Could be your IT people have anticipated and setup a 'smart host' in Sendmail's localhost - send only service.

One way to check ... the test message you got in your inbox.   Look at the full header of that message and read the lines that say 'received by' ... those are the mail systems that message went through to get to the destination.

 'SoS', Ken

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

Re: Receive notifications on forum posts

by Jose M. -
Hi Visvanath and Ken,
I have already created a forum with test users where I am performing all the analysis, I will contact with IT to check those headers of the emails received and check if they can see somehting about the missing emails, no much hope expected...

EDIT. Another test I can think of is to install moodle locally with a different email account server and perform the same tests. 
In reply to Jose M.

Re: Receive notifications on forum posts

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
> Another test I can think of is to install moodle locally with a different email account server and perform the same tests.

We know that Moodle sends notification mail, in general! It is the specific server you/your IT need to debug. Control experiments do not help much, I'm afraid.
Average of ratings: Useful (1)
In reply to Visvanath Ratnaweera

Re: Receive notifications on forum posts

by Jose M. -

Hi,

I have run a portable version of Moodle (link) and the same thing happens to me, both the test email and the direct message to user work, but not the forum message notifications, so there must be something wrong on my side, please look at the attached screenshots of the forum preferences and user preferences, am I missing something?

Attachment forum preferences.png
Attachment forum.png
Attachment notification preferences.png
In reply to Jose M.

Re: Receive notifications on forum posts

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
Are you talking to me? This is what I said:

>>> You need to change the strategy to a targeted approach - which is by reading the log file of the SMTP server.

>> It is the specific server you/your IT need to debug. Control experiments do not help much, I'm afraid.

BTW, have you posted a screen-shot of your outgoing mail settings?

Average of ratings: Useful (1)
In reply to Visvanath Ratnaweera

Re: Receive notifications on forum posts

by Jose M. -
Hi Ken,
Here is a screenshot of the outgoing mail settings, basically they are the default settings except for the data shown in the screenshot and the reply email, which matches the SMTP username. 
Attachment outgoing.jpg
In reply to Jose M.

Re: Receive notifications on forum posts

by Ken Task -
Picture of Particularly helpful Moodlers
Ok, is this screen shot of that 'portable' (Windows) version of Moodle?
And this is installed on a local Windows machine - not a server on the internet, right?
If you are using this 'portable' vesion of moodle for testing purposes, but have a linux server hosted on the internet, they are NOT ... repeat *NOT* ... the same environment.

Does this 'package' come with Windows equiv of SendMail - the grand-daddy of all mail servers (linux)?   It would have to be some .exe that comes with the 'portable' package - and it's probaby not very sophisticated.

I see there is no ... repeat no .. SMTP security setting ... left to default which is none.
Wow! sad   Spammers would love to know where that is located ... they would have a field day with that!

I asked if you would please look at the header of one of those test messages that you did receive.    Did you do that?  And to check all the lines in that header for 'Received by' ... those are the mail servers that message ran through to get to destination.   Take a look at the header of one of the messages you get from this forum to get an idea of what valid email looks like.

A single test message might sneak through but a forum distribution of a messages to what might be 1000's of users, probably won't ... especially IF the SMTP server doesn't have an MX record in DNS, a SPF record in DNS, and a DKIM record in DNS now-a-days.

Mr. V is right ... Moodle will try to send ... that's all it can do .. it's NOT a mail server.   And IF the settings you have for SMTP work, then you need to check the logs of that SMTP server.

'SoS', Ken

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

Re: Receive notifications on forum posts

by Jose M. -
Hi Ken,
Yes, the screenshot is from a portable version of Moodle, and the environment is not the same, one is a local Windows machine and the other is a Linux server on the internet, hence the lack of SMTP security, it was intended to be a quick install to test the email while getting the information from IT.
The response from IT is no records found, as if Moodle is not sending the emails to the SMTP server. Can I check somewhere else, maybe in administration or database directly if it is as he said?
In reply to Jose M.

Re: Receive notifications on forum posts

by Ken Task -
Picture of Particularly helpful Moodlers
"it was intended to be a quick install to test the email while getting the information from IT"

Different Environment ... your 'testing' is, to me at least, useless.  Now if you had a development instance of moodle on same Linux server which is on internet, then testing might be valid.

"No records found .. Can I check somewhere else"

If we are talking about a DB query of some sort and you have no access to make such queries, guess you.will have to believe whomever supplied that info.   Servers on internet do keep logs *outside* of Moodle logs - moodle only logs it's own stuff to DB.   Sending of emails, any kind, moodle logs would probably show it's done it's job in composing whatever in an email format, and then attempts to send via whatever as configured.   Server logs would be involved at that point and if you have no access to true server logs, then no way to really verfiy - cept at the receiving end and if it's not getting there then??????

'SoS', Ken






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

Re: Receive notifications on forum posts

by Jose M. -
Hi Ken,
I have access to the database, I have queried mdl_logstore_standard_log table but only found failed emails, I have been able to filter by message_sent or notification_sent but it does not show info about the content. I have been reading and it is not an easy task, I need a workaround to store a log of sent emails and then, start digging. At least, I need a method to prove to IT that Moodle is working and the SMTP server is not.
In reply to Jose M.

Re: Receive notifications on forum posts

by Jose M. -
I have read an article that I can create a new event in moodlelib.php to register the sent email, but I have not found a clear tutorial to do it and I am afraid of breaking something :S
In reply to Jose M.

Re: Receive notifications on forum posts

by Ken Task -
Picture of Particularly helpful Moodlers
Just to be clear ... we are now talking your true server and NOT that Windows test system, right?

If so mind sharing some info about your server?   Much can be gathered from php info.
Don't share anything sensitive ... no logins/password, not even URL to server.
But things like operating system is? etc.   You could PM me the url to your moodle server and I'll volunteer to do some non-evasive testing.

"... prove to IT that Moodle is working and the SMTP server is not."

This is beginning to sound like we need a better working relationship with 'IT' - but that's my impression of what you've posted. sad   I have, in my former working life, walked in all roles shoes ... as teacher in a moodle and then later as Moodle admin/Server admin.  Different perspective believe me.  Your IT people might be doing all they can do ... priority of entity is such that moodle is last on the list.   Besides that, one has to immerse themselves into moodle application and many IT simply don't have the time ... nor the inclination.

All that being said ...

Mind sharing what tutorial/whatever you found on setting up events?
And, yes, good idea to be cautious about attempting setup of anything related to this issue as it's true, you could be making matters worse than they are.

Moodle is an application server designed to provide online learning ... it is not and never has been a mail server - even though there are modules related to email.

Dunno what you will find but you could try using a tool:
Run test on the FQDN of the moodle server as well as the FQDN of the SMTP server.

So we know you have access to the moodle admin only.   What if you requested command line access to the server?   And promised IT you would not do anything to make their jobs harder?   You would have to learn a little linux command line foo ... are you willing to do that?

If you want to risk starting an internal struggle with IT to 'prove' SMTP isn't working, you could create a System Admins (SA) category ... hidden ... and inside SA a hidden System Admins Course (sac).    Inside that course, set up an IT person as student (manual accounts) and confirm their account.   Also acquire an email account on some other system - you know login/password to that account and can access that accounts email.

In the sac course, setup an Announcements forum and force subscribe all users in that course to that forum.  You don't have to make yourself teacher of that course but could to be a true test.   That really won't be a valid test for courses that your server has with 1000's of users forced subscribed to a forum, but you should be able to get mail from your moodle on that other account's email and be able to check the header of those messages.

'SoS', Ken

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

Re: Receive notifications on forum posts

by Jose M. -
Hi Ken,

Yes, we are talking about the production machine, sorry the misunderstanding.

The server runs Moodle 4.2+ on an Ubuntu Server 22.04.3 machine and PHP 7.4, if you need more info I can mp you.

About IT, well, they send to me the information I request, like SMTP logs, but not are really on it, which is why I have to do everyting possible on my side before I drop the ball on them.

The tutorial is not properly a tutorial is like pseudo-code, what to do but not how to do it, link: https://tracker.moodle.org/browse/MDL-51386.

After launching the scan in mxtoolbox, the only warning is in SMTP Banner Check, Reverse DNS does not match SMTP Banner.

Yes, I have access to moodle admin and also command line, I installed and configured all the whole Moodle-Database package so I am not afraid to execute unix commands.

I have aalready created a test course but I am not sure what System Admins Course is or if it is a different way to create courses. Yesterday I tried retrieve the forgotten password and the email worked perfectly and fast, why mail works in all cases but not in the forum is shocking me.
In reply to Jose M.

Re: Receive notifications on forum posts

by Ken Task -
Picture of Particularly helpful Moodlers
If you got one message back/through then you have something to look at the full headers.
Do that.   Check each line in the header above the subject line of the header and note the ones that say 'received by'.    Those are the mail servers that message ran through.

I see by your PM that the mail server *isn't* on the same network as the moodle ... therefore multiple hops away from each other.   

Mail server rules ... something like:
mail sent to users on this system - no SMTP relay
mail sent to users on OTHER systems, use SMTP relay.

Use that FQDN for the mail server in the mxboxtool.

'SoS', Ken


Average of ratings: Useful (1)
In reply to Jose M.

Re: Receive notifications on forum posts

by Ken Task -
Picture of Particularly helpful Moodlers
Use the mail server FQDN with mxtoolbox. There's a diff!
You say you have command line access to the server so there would be servers logs I would think.
/var/log/maillog? /var/log/apache2/access_log or error_log or ssl_access_log ssl_error_log.
Can you sudo to root and install software?
If so, install 'alpine' - a text based MTA.
Access alpine as a user ... not root ... config alpine as is ... try to send yourself on true mail server a message.
Alpine can be configured to use SMTP relay as well.

Forum postings are not same as individual messages ... mutliple users for one - therefore should NOT be 'shocking'!

'SoS', Ken
Average of ratings: Useful (1)
In reply to Jose M.

Re: Receive notifications on forum posts

by François Lizotte -
My two cents: Moodle 4.2 requires PHP 8.0 minimum (https://moodledev.io/general/releases/4.2).
Average of ratings: Useful (2)
In reply to François Lizotte

Re: Receive notifications on forum posts

by Ken Task -
Picture of Particularly helpful Moodlers
Hmmmm ... Mr. Lizotte might be right!!!!

"The server runs Moodle 4.2+ on an Ubuntu Server 22.04.3 machine and PHP 7.4,"

I wonder ... from command line, cd /path/to/moodlecode/admin/cli/
php checks.php [ENTER]

Above assumes the php above finds php-cli for 7.4 on server.

'SoS', Ken

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

Re: Receive notifications on forum posts

by Jose M. -
Hi Ken,
When I execute the php command in command line I get two errors:
- tool_task_maxfaildelay: 2 failed tasks.
- tool_task_adhocqueue: The oldest task is 303 days old, which is more than 4 hours old
In reply to François Lizotte

Re: Receive notifications on forum posts

by Jose M. -
Hi François,
I remember struggling with php and moodle versions in the beginning when installing phpmyadmin and other tools, it was really a headache until I realize the error. Now I see in /etc/php/ folders with versions 8.0, 8.1 and 8.2. I need to test the change in a test environment and check outgoing mail and cross my fingers.
In reply to Jose M.

Re: Receive notifications on forum posts

by Ken Task -
Picture of Particularly helpful Moodlers
Follow up ...
Your package (a zip file) has a fake sendmail.exe.
In the readme that comes with that portion of the package it says:
"it doesn't support deferred delivery, and requires an smtp server to perform
the actual delivery of the messages
"
The install step 3
"configure smtp server and default domain in sendmail.ini"

'SoS', Ken

Average of ratings: Useful (2)