ISP provider limits number of sent messages :-(

ISP provider limits number of sent messages :-(

by Francis Vendrell -
Number of replies: 7

Hello,

My ISP provider limits the number of sent messages to 50 per minute.

As a consequence a message posted in a forum is sent to only 49 users when the cron is executed.

A way to sort out this problem would be to make a pause of 2 seconds between each message sent.

This could be done by adding the "sleep(2)" php fonction somewhere in the code. I tried to insert it in several places into the file lib/phpmailer/class.smpt.php but I could not make it works. Probably this is not the right way to do it.

I would really appreciate any advice given to circumvent this limit.


Average of ratings: -
In reply to Francis Vendrell

Re: ISP provider limits number of sent messages :-(

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers

I know what you mean.  GoDaddy, for example, does the same thing.

But for me, the fix was simple.  I asked GoDaddy to increase my limit, and they did.  I just had to agree that I was not sending spam.  I requested 4000 per day, and they did this for me.

In reply to Francis Vendrell

Re: ISP provider limits number of sent messages :-(

by Andrew Lyons -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi Francis,

Thanks for raising this issue. I'm not really sure whether this is something that we can easily, or should really fix within Moodle. To be honest, it seems that your host has implemented this rate limiting in a strange way. It is the job of the Mail Transfer Agent (MTA) to transfer the messages you pass it  to the next point in the queue. If the MTA is unable to deliver them immediately, it is *meant* to queue them until such a time that it can send them.

Moodle does not handle these kinds of failures well - it has no way of doing so as it was never really designed with this in mind. In the case of forum emails, we have a single flag for each discussion - if you have 100 users subscribed to the same discussion, we only mark that discussion as sent once - not once per user.

If you really want to hack Moodle to do this, then you can do so - it is Open Source after all, but this is not a change that I would be keen to support.

The easiest way to hack this into Moodle is to edit lib/moodlelib.php - Find this line: https://github.com/moodle/moodle/blob/v2.9.1/lib/moodlelib.php#L5657, and just before the "return true;" line, add a sleep(2).

As I say, I don't think that Moodle is the best place to perform this kind of rate limiting, and that you should persuade your host to re-consider the way in which they rate limit e-mail. Perhaps they could whitelist certain domains for example.

Hope this helps,

Andrew

Average of ratings: Useful (1)
In reply to Andrew Lyons

Re: ISP provider limits number of sent messages :-(

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers

Andrew, your post made me think about several other alternatives, in addition to what I mentioned above.

1) On my small Moodle, I stagger due dates for discussions among courses.  I could easily make all discussions for (let's say, 5) courses due on Friday evening.  However, many of the students like to wait until the last moment to make posts, which can then overwhelm my server's email limits.  Instead, I make posts for one or two courses due Friday night, then for another course Thursday night, then for another course Sunday night, etc.  I think you get the idea.

2) You can encourage students to switch their "email digest type" to "daily emails".  This will consolidate all of the daily posts into one email.  I am unsure if this can be made the default within Moodle, but many students often prefer this setting (although I do not).

Average of ratings: Useful (2)
In reply to Rick Jerz

Re: ISP provider limits number of sent messages :-(

by Andrew Lyons -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi Rick,

Thanks for those suggestions - also good options. It's a shame when it's one point in the chain which makes things difficult like this.

Your post has however reminded me why this cannot be done in Moodle, even with the best will in the world. Sometimes we do send e-mails based on a direct user interaction (and not cron). One example of this is when sending messages to multiple users using the participants listing. This will be affected by the suggested change - perfect, that's what we want. However, if your site is more active, and five of your teachers send messages at the same time, then they may still hit that rate limit and have messages rejected.

Web applications are not a single thread. There may be 1 connection, but just as easily there may be 1,000. If each of those connections sends an e-mail at the same time, that sleep hack won't work.

Andrew

In reply to Andrew Lyons

Re: ISP provider limits number of sent messages :-(

by Francis Vendrell -

Hello Andrew,

Thank you very much for your detailed answer!

I understand that it is not the role of Moodle to provide such a service. So I bought an SMTP service for mass mailing. This solved my problem.

I wonder if adding the line sleep(2) may trigger others problems.

For example, it would take 1800 sec at least to send a message to 900 users, i.e 30 minutes.
But the cron job may run every 5 minutes.
So there will be some kind of mismatch beetwen two succesive cron jobs.

Do you think that in this case all users will receive the email?

I thus asked the issue https://tracker.moodle.org/browse/MDL-50707 to be cancelled.


In reply to Francis Vendrell

Re: ISP provider limits number of sent messages :-(

by Andrew Lyons -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Thanks for your understanding Francis,

I agree, adding a two-second sleep does have the potential to cause other problems. I imagine that it will also increase the load on the server unnecessarily.

With regards your question about cron, this should not matter. Most of the mailing in Moodle is written with this in mind. For example, with regards forum e-mails, we mark a forum post as having been mailed out before we mail out. This means that if cron fails during the send, then some users may not receive messages, but at the same time it means that others do not receive duplicates. In some cases, if a failure is repeatable (e.g. something wrong with a user account causes an exception to be thrown), this loop may never end.

Hope that this helps, and good luck with your SMTP service,

Andrew

In reply to Francis Vendrell

Re: ISP provider limits number of sent messages :-(

by Rajat Sharma -
I use Godaddy for my site http://www.govtvacancy.in/ and it is good there is no issue. You have to contact to the administrator for your query may be some technical problem.