diff --git a/frappe/email/bulk.py b/frappe/email/bulk.py index fcf2e9de6a..9b69458526 100644 --- a/frappe/email/bulk.py +++ b/frappe/email/bulk.py @@ -230,7 +230,7 @@ def flush(from_test=False): frappe.db.sql("""update `tabBulk Email` set status='Expired' where datediff(curdate(), creation) > 3""", auto_commit=auto_commit) - for i in xrange(500): + for i in xrange(100): email = frappe.db.sql("""select * from `tabBulk Email` where status='Not Sent' and ifnull(send_after, "2000-01-01 00:00:00") < %s order by priority desc, creation asc limit 1 for update""", now_datetime(), as_dict=1) @@ -265,6 +265,9 @@ def flush(from_test=False): frappe.db.sql("""update `tabBulk Email` set status='Error', error=%s where name=%s""", (unicode(e), email["name"]), auto_commit=auto_commit) + finally: + frappe.db.commit() + def clear_outbox(): """Remove mails older than 31 days in Outbox. Called daily via scheduler.""" frappe.db.sql("""delete from `tabBulk Email` where diff --git a/frappe/utils/__init__.py b/frappe/utils/__init__.py index 418bdf4b8c..f197a1c14a 100644 --- a/frappe/utils/__init__.py +++ b/frappe/utils/__init__.py @@ -75,7 +75,11 @@ def validate_email_add(email_str, throw=False): match = re.match("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", email.lower()) if not match: - return False + if throw: + frappe.throw(frappe._("{0} is not a valid email id").format(email), + frappe.InvalidEmailAddressError) + else: + return False matched = match.group(0)