浏览代码

[hotfix] check daily email limit before sending emails

version-14
mbauskar 8 年前
父节点
当前提交
ce8f76ff4a
共有 1 个文件被更改,包括 12 次插入0 次删除
  1. +12
    -0
      frappe/email/queue.py

+ 12
- 0
frappe/email/queue.py 查看文件

@@ -218,9 +218,17 @@ def check_email_limit(recipients):
or frappe.flags.in_test): or frappe.flags.in_test):


monthly_email_limit = frappe.conf.get('limits', {}).get('emails') monthly_email_limit = frappe.conf.get('limits', {}).get('emails')
daily_email_limit = frappe.conf.get('limits', {}).get('daily_emails')


if frappe.flags.in_test: if frappe.flags.in_test:
monthly_email_limit = 500 monthly_email_limit = 500
daily_email_limit = 50

# get count of today's sent mails
today = get_emails_sent_today()
if daily_email_limit and (today + len(recipients)) > daily_email_limit:
throw(_("Cannot send this email. You have crossed the sending limit of {0} emails for this day.").format(daily_email_limit),
EmailLimitCrossedError)


if not monthly_email_limit: if not monthly_email_limit:
return return
@@ -236,6 +244,10 @@ def get_emails_sent_this_month():
return frappe.db.sql("""select count(name) from `tabEmail Queue` where return frappe.db.sql("""select count(name) from `tabEmail Queue` where
status='Sent' and MONTH(creation)=MONTH(CURDATE())""")[0][0] status='Sent' and MONTH(creation)=MONTH(CURDATE())""")[0][0]


def get_emails_sent_today():
return frappe.db.sql("""select count(name) from `tabEmail Queue` where
status='Sent' and DATE(creation)=CURDATE()""")[0][0]

def get_unsubscribe_message(unsubscribe_message, expose_recipients): def get_unsubscribe_message(unsubscribe_message, expose_recipients):
if unsubscribe_message: if unsubscribe_message:
unsubscribe_html = '''<a href="<!--unsubscribe url-->" unsubscribe_html = '''<a href="<!--unsubscribe url-->"


正在加载...
取消
保存