News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

How to get instant email notifications?

Started by willemb, May 13, 2022, 10:07:33 AM

Previous topic - Next topic

willemb

We have a small closed forum with 200 users but around 50 are actually regularly active. We have cases where it is important that all followers of a board get an email notification of a new topic/reply straight away. All have the appropriate notification setting. This used to work fine, but since about 6-9 months we are sometimes seeing delays of half an hour up to almost a day. Upgrading from 2.1 RC2 to 2.1.2 did not improve this.

Looking at the e-mail headers the delay is in the sending out by SMF.
I have been playing with the settings at Administration Center > Mail > Settings, but that does not seem to make any difference. I never see anything in the queue.

My impression is that notification works better when multiple people are active and that the delays occur when only the poster is logged in.

So my questions are:

  • What exactly triggers the notification email? It looks like clicking POST is is not enough to make it go out. I could not find documentation about this
  • What can I do to make them being send straight away in all cases? We use SMTP and a sending service based on Spamexperts. Also the volumes are very low so there is no risk of getting blacklisted.

Kindred

There are no suggestions.  Smf does not do "instant" notification.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Arantor

Well, it does if you have something clearing the email queue promptly... but this is not documented or described anywhere.

willemb

But in the end everyone gets their notification. Is it documented somewhere what triggers the sending? I don't understand how it works. Queue length is always 0, even when I just posted something.

Kira_

Quote from: willemb on May 13, 2022, 10:07:33 AMWhat can I do to make them being send straight away in all cases?

Try to find in Subs-Post.php
// Are we using the mail queue, if so this is where we butt in...
    if ($priority != 0)
        return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private);

    // If it's a priority mail, send it now - note though that this should NOT be used for sending many at once.
    elseif (!empty($modSettings['mail_limit']))
    {
        list ($last_mail_time, $mails_this_minute) = @explode('|', $modSettings['mail_recent']);
        if (empty($mails_this_minute) || time() > $last_mail_time + 60)
            $new_queue_stat = time() . '|' . 1;
        else
            $new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1);

        updateSettings(array('mail_recent' => $new_queue_stat));
    }

and replace it

    if (!empty($modSettings['mail_limit']))
    {
        list ($last_mail_time, $mails_this_minute) = @explode('|', $modSettings['mail_recent']);
        if (empty($mails_this_minute) || time() > $last_mail_time + 60)
            $new_queue_stat = time() . '|' . 1;
        else
            $new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1);

        updateSettings(array('mail_recent' => $new_queue_stat));
    }

This should disable the message queue.
Don't forget to make a backup copy of the file.
а нас
за що?

Kira_

Quote from: willemb on May 13, 2022, 01:17:51 PMI don't understand how it works.
In short, emails are sent by function sendmail in a file Subs-Post.php

If the priority of the letter is zero, it sends the letter itself, otherwise it adds the letters to the queue.

Emails from the queue are sent by function ReduceMailQueue in the file ScheduledTasks.php
а нас
за що?

Arantor

I do love people who suggest things I worked on should be disabled rather than properly configured for the situation at hand. I also hope your host doesn't limit you otherwise this change will cause emails to disappear.

Kira_

This is a very special case, which is very necessary for a single person. The rest are happy :)
а нас
за що?

willemb

Sorry guys, I can't read PHP code. What situation makes SMF decide to send them? A new user logs in? 5 new posts?
In our profiles, under Alert Preferences we have "How frequently to tell me: Immediately". Well, email is never immediately, but until about 9 months ago notifications arrived within 15 minutes or so. After that the delays came and they are very unpredictable. Sometimes half an hour, sometimes 17 hours.
BTW for this topic I get an email notification for each new reply within 1 minute! That's what I want as well.

Arantor

Basically every page visit by anyone can theoretically trigger sending something from the queue, assuming 1) there is something in the queue, 2) it wouldn't push it over the defined limit per hour and 3) the number of items per page load hasn't been hit.

I've seen this site take 3-4 *hours* to send me notifications. But this site is significantly busier and has customisations that have never been documented - like how to send email from system cron. And they've never been shared.

Kira_

In simpler words. The forum does not perform any actions as long as no one comes to it. When emails are added to the queue, they will remain there until someone opens any forum page. If there are few users, it may take a long time. As soon as someone opens the forum page, several emails from the queue will be sent. The quantity depends on the settings. Then there is a pause in sending emails (also in the settings) and everything repeats while there are emails in the queue.
а нас
за що?

willemb

Thanks, Arantor and Kira_! It is clear now what is going on.
The documentation mentions a setting "Enable Mail Queue". This is missing at my mail settings panel. But under "Maximum emails to send per minute" there it says "(Set to 0 to disable.)" Disable queueing?

Arantor

The documentation has never actually been updated - the setting to disable the queue (as 2.0 originally had) was removed 8 or 9 years ago.

The 0 to disable won't disable queueing, it'll disable checking how many to send per minute, so it'll try and send as many as it can in the queue in a minute.

willemb

OK, I can reproduce what you described. All is clear now. I still might try Kira's dangerous hack later this weekend. Our host has no real limit but advises < 300 per hr. With this small club we'll never hit that.

On a bit longer term I will have to look for another form of notification. A growing part of my users wants their huge phone to vibrate.

Kira_

If you have access to the cron of your (or any) server, the simplest solution is to add the task "wget -q -t1 /dev/null http://YOUR_FORUM" to the cron.
This command will download the main page of the forum to nowhere every for example 30 minutes, and all the tasks planned by the forum will be completed.
а нас
за що?

willemb

Thanks Kira_, that looks like an elegant solution! Our forum is closed and it will probably not work for the login page. So I'll have to add credentials to the wget. I'm still working on my cron and wget skill to do that in a safe way. I might do it from my NAS at home.

Kira_

It is not necessary for the user to log in to the forum. It's enough for him to load ANY forum page. Even if it is a page with an error.  For example, that the forum is closed or the password entry page.
а нас
за що?

Johnfromhere

I run a forum with fewer than 40 members and would like to ensure that notification emails are sent immediately.
Is the mod to 'Subs-Post.php' in this thread OK to use please?

If not, is there any alternative.

I am not able to set up a cron job on the server.

Many thanks.

John.

willemb

Quote from: Johnfromhere on May 09, 2023, 11:58:38 AMIs the mod to 'Subs-Post.php' in this thread OK to use please?

I never tried that. In the end I found an GUI a bit hidden in our hosts DirectAdmin panel that allowed me to set up cron tasks. It even became a new hobby. I have cron tasks now kicking several WordPress sites and Nextcloud.

Are you sure your host didn't hide something like that deep in cPanel, Plesk or whatever?

Johnfromhere

Hmmm...  Thanks.

I'll have a closer look.

Cheers.

John.

Johnfromhere

I couldn't manage to sort a cron job.

As I said, the forum I run has less than 40 members (in fact nearer 20!).
Is there a parameter I can alter or just paste the code quoted above into the requisite file?

Any help gratefully received.

Cheers.

John.

Johnfromhere

I need to do something to get email sent to my (at most 20) members immediately they are posted.  I am not au fait enough with setting up a cron job.

I do not want to disable stuff you wrote Arantor, simply to modify it to meet MY needs.

Can anyone help, please?

Many thanks in anticipation.

Cheers.

John.

Sesquipedalian

SMF sends emails in batches of 50, which means that on a forum as small as yours, a single call to SMF's cron.php file will send them all.

In the scenario you are concerned about—namely, sending notifications about new posts as soon as they are made—SMF's default "web cron" method should be completely sufficient. After a user submits a post, the very next page load will trigger the background task to run.

If the notifications are not being sent immediately to everyone, the most likely cause is that some or all of your users simply haven't chosen to be notified immediately about new posts in their notification preferences.

SMF's default for this is "Immediately, but only for the first new message," which means that only one notification will be sent until the next time the user logs in. The other options are immediately, once per day, and once per week.

To be notified immediately about every new post individually, users need to update their notification preferences to select that option. As an admin, you have the power to change that preference for them, but you should generally only do that after confirming with the user that that's really what they want. Sending notifications to people more often than they want usually annoys them and drives them away.
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

Johnfromhere

Many thanks.

I'll keep an eye on it.

Thanks again.

Cheers.

John.

Johnfromhere

My forum has 29 members and a posting notification took 2+ days to arrive after the posting! I admit that the forum is (incredibly) quiet at the moment but is there any way apart from setting up a cron job to load the page to nowhere?

I accept the fact that you won't get any more notifications until you read the posting you have been notified about.

Sorry but I don't understand:-
QuoteThe other options are immediately, once per day, and once per week.

Cheers.

John.

willemb

John, I think your options are:
  • Theach all 29 members to 'hard refresh' the page after they posted somthing
  • Reconsider your cron options. Any shared webhosting I've seen has it, but it is always hidden somewhere deep in the control panel (cPanel, DirectAdmin, Plesk etc). Ask your provider
  • It doesn't have to run on the same server. You could set op some other trick that just accesses your home page every half hour or so.

Johnfromhere


Advertisement: