Try ERPNext Try Frappe Cloud Buy Support Partners Foundation

Changing Email Queue sending Interval

I noticed when we send an email of invoice it gets in the queue. Queue is executed every 7 mins.

However this does not happens with high priority mails like password reset or welcome mail.

I am interested in lowering the time for email queue execution from 7 mins to maybe 2 mins or rather eliminate the queue altogether. Which are the best options and some thoughts on implementing it ?

1 Like

@srajelli Normally emails from Frappe are sent as ‘bulk emails’ (sales orders etc), whereas password reset emails etc are sent on priority.

By maintaining a email queue we balance the server load etc. Hence the delay. Any particular reason why you wish to eliminate the email queue ?

I just want the email to be sent on priority or at least reduce the 7 mins queue time

@anand maybe you could suggest something

@srajelli Fixed in v7. High priority mails like welcome and password reset get sent immediately now.

Thanks I noticed it , But can we do the same for regular emails (Sales Invoice, PO etc) ?

3 Likes

Hi @srajelli, any news for this?

Thanks

Nope it’s still the same for other documents

I have the same problem and searching for solution

You can write a custom script and add a custom button to forms to send high priority emails. I haven’t done this but I am sure it is possible

If “Send Immediately” was an option in the email form, it would satisfy my needs as well. I’m not sure how one would go about adding this or setting the email priority to bypass the scheduler.

1 Like

Hi all,

I know this is old, but this seems to be an open topic. I did a bit of digging and found that in ./config/supervisor.conf there is a definition of the workers, containing

[program:frappe-bench-frappe-short-worker]
command=/usr/local/bin/bench worker --queue short
priority=4
autostart=true
autorestart=true
stdout_logfile=/home/frappe/frappe-bench/logs/worker.log
stderr_logfile=/home/frappe/frappe-bench/logs/worker.error.log
user=frappe
stopwaitsecs=360
directory=/home/frappe/frappe-bench
killasgroup=true
numprocs=1
process_name=%(program_name)s-%(process_num)d

As far as I understand, the short worker is used to send mails. stopwaitsecs is the duration, how long this will be kept alive, so unfortunately, this does not impact the send interval…

Then, I found that in hooks.py, the email queue is flushed with the all trigger (~every 4 minutes according to https://frappe.io/docs/user/en/tutorial/task-runner). So, I have added to my custom app in the hooks.py the following block:

 scheduler_events = {
    "cron": {
        "* * * * *": [
            "frappe.email.queue.flush"
        ]
    }
}

This seems to run the queue every minute…

8 Likes

Hi, I am also looking for the same solution to reduce the mailing interval. Can you please confirm the same method is applicable in v11.1.18?

I am from a non-tech background. How can I achieve the same?

Kindly help.

Ashin

Yes it will work for v11.x

Thanks.

Hi,
Actually, this doesn’t work for me. I am using V13. I have added the required lines on my custom app hooks.py

Is there anything else I need to do?

This should also work in V13… Alternatively, instead of using the hooks, you could directly put this into your crontab

* * * * * cd /home/frappe/frappe-bench && bench execute frappe.email.queue.flush
1 Like

This works perfectly. Thanks for your reply.

Can you please explain how to do this? Thanks.

To add this to you (ideally root) crontab, do (this applies for Debain/ubuntu)

$ sudo crontab -e

then enter the above line at the end of the file and hit CTRL-X, Y, ENTER (in case of nano as your editor of choice).