diff --git a/frappe/email/doctype/email_account/test_email_account.py b/frappe/email/doctype/email_account/test_email_account.py index 53e405a27b..57645a2b29 100644 --- a/frappe/email/doctype/email_account/test_email_account.py +++ b/frappe/email/doctype/email_account/test_email_account.py @@ -16,6 +16,7 @@ class TestEmailAccount(unittest.TestCase): def setUp(self): email_account = frappe.get_doc("Email Account", "_Test Email Account 1") email_account.db_set("enable_incoming", 1) + frappe.db.sql('delete from `tabEmail Queue`') def tearDown(self): email_account = frappe.get_doc("Email Account", "_Test Email Account 1") diff --git a/frappe/email/queue.py b/frappe/email/queue.py index 96f4416424..bf708d954b 100755 --- a/frappe/email/queue.py +++ b/frappe/email/queue.py @@ -275,18 +275,21 @@ def flush(from_test=False): def make_cache_queue(): '''cache values in queue before sendign''' cache = frappe.cache() - cache.delete_value('cache_email_queue') - for l in frappe.db.sql('''select name from `tabEmail Queue` + emails = frappe.db.sql('''select name from `tabEmail Queue` where status='Not Sent' and (send_after is null or send_after < %(now)s) order by priority desc, creation asc - limit 500''', { 'now': now_datetime() }): - cache.lpush('cache_email_queue', l[0]) + limit 500''', { 'now': now_datetime() }) + + cache.delete_value('cache_email_queue') + for e in emails: + cache.lpush('cache_email_queue', e[0]) def send_one(email, smtpserver=None, auto_commit=True, now=False): '''Send Email Queue with given smtpserver''' - email = frappe.db.sql('''select name, status, communication, message, sender, recipient + email = frappe.db.sql('''select name, status, communication, + message, sender, recipient, reference_doctype, from `tabEmail Queue` where name=%s for update''', email, as_dict=True)[0] if email.status != 'Not Sent': # rollback to release lock and return