From 85f24c694c6612988c8a908fc7996c6411e193cf Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Wed, 21 Sep 2016 11:25:50 +0530 Subject: [PATCH 1/3] [minor] keep backups 24 hours old instead of 48 hours --- frappe/utils/backups.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/utils/backups.py b/frappe/utils/backups.py index 2ef96cc27d..0e3e57e3f6 100644 --- a/frappe/utils/backups.py +++ b/frappe/utils/backups.py @@ -166,7 +166,7 @@ def scheduled_backup(older_than=6, ignore_files=False, backup_path_db=None, back return odb def new_backup(older_than=6, ignore_files=False, backup_path_db=None, backup_path_files=None, backup_path_private_files=None, force=False): - delete_temp_backups(older_than = frappe.conf.keep_backups_for_hours or 48) + delete_temp_backups(older_than = frappe.conf.keep_backups_for_hours or 24) odb = BackupGenerator(frappe.conf.db_name, frappe.conf.db_name,\ frappe.conf.db_password, backup_path_db=backup_path_db, backup_path_files=backup_path_files, From ed8021c5399bc51af0df1dbf1d4278aa25b22f3e Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 22 Sep 2016 11:41:50 +0530 Subject: [PATCH 2/3] [minor] retry if disconnected while sending email --- frappe/__init__.py | 6 +++--- frappe/core/doctype/user/user.py | 4 +++- frappe/email/__init__.py | 12 ++++++----- frappe/email/smtp.py | 34 +++++++++++++++++++++----------- 4 files changed, 35 insertions(+), 21 deletions(-) diff --git a/frappe/__init__.py b/frappe/__init__.py index f049c2e935..34b8ca29a7 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -359,7 +359,7 @@ def sendmail(recipients=(), sender="", subject="No Subject", message="No Message unsubscribe_method=None, unsubscribe_params=None, unsubscribe_message=None, attachments=None, content=None, doctype=None, name=None, reply_to=None, cc=(), show_as_cc=(), message_id=None, in_reply_to=None, send_after=None, expose_recipients=False, - send_priority=1, communication=None): + send_priority=1, communication=None, retry=1): """Send email using user's default **Email Account** or global default **Email Account**. @@ -396,11 +396,11 @@ def sendmail(recipients=(), sender="", subject="No Subject", message="No Message if as_markdown: frappe.email.sendmail_md(recipients, sender=sender, subject=subject, msg=content or message, attachments=attachments, reply_to=reply_to, - cc=cc, message_id=message_id, in_reply_to=in_reply_to) + cc=cc, message_id=message_id, in_reply_to=in_reply_to, retry=retry) else: frappe.email.sendmail(recipients, sender=sender, subject=subject, msg=content or message, attachments=attachments, reply_to=reply_to, - cc=cc, message_id=message_id, in_reply_to=in_reply_to) + cc=cc, message_id=message_id, in_reply_to=in_reply_to, retry=retry) whitelisted = [] guest_methods = [] diff --git a/frappe/core/doctype/user/user.py b/frappe/core/doctype/user/user.py index 0d8802e990..1b5249a30a 100644 --- a/frappe/core/doctype/user/user.py +++ b/frappe/core/doctype/user/user.py @@ -209,9 +209,11 @@ class User(Document): from frappe.utils import get_url link = self.reset_password() + self.send_login_mail(_("Verify Your Account"), "templates/emails/new_user.html", {"link": link, "site_url": get_url()}) + def send_login_mail(self, subject, template, add_args, now=None): """send mail with login details""" from frappe.utils.user import get_user_fullname @@ -238,7 +240,7 @@ class User(Document): frappe.sendmail(recipients=self.email, sender=sender, subject=subject, message=frappe.get_template(template).render(args), - delayed=(not now) if now!=None else self.flags.delay_emails) + delayed=(not now) if now!=None else self.flags.delay_emails, retry=3) def a_system_manager_should_exist(self): if not self.get_other_system_managers(): diff --git a/frappe/email/__init__.py b/frappe/email/__init__.py index 42b66d7f4b..e8159d249d 100644 --- a/frappe/email/__init__.py +++ b/frappe/email/__init__.py @@ -9,20 +9,22 @@ from frappe.email.smtp import send from frappe.utils import markdown def sendmail_md(recipients, sender=None, msg=None, subject=None, attachments=None, content=None, - reply_to=None, cc=(), message_id=None, in_reply_to=None): + reply_to=None, cc=(), message_id=None, in_reply_to=None, retry=1): """send markdown email""" - sendmail(recipients, sender, markdown(content or msg), subject, attachments, reply_to=reply_to, cc=cc) + sendmail(recipients, sender, markdown(content or msg), subject, attachments, + reply_to=reply_to, cc=cc, retry=retry) def sendmail(recipients, sender='', msg='', subject='[No Subject]', attachments=None, content=None, - reply_to=None, cc=(), message_id=None, in_reply_to=None): + reply_to=None, cc=(), message_id=None, in_reply_to=None, retry=1): """send an html email as multipart with attachments and all""" - mail = get_email(recipients, sender, content or msg, subject, attachments=attachments, reply_to=reply_to, cc=cc) + mail = get_email(recipients, sender, content or msg, subject, attachments=attachments, + reply_to=reply_to, cc=cc) if message_id: mail.set_message_id(message_id) if in_reply_to: mail.set_in_reply_to(in_reply_to) - send(mail) + send(mail, retry=retry) def sendmail_to_system_managers(subject, content): send(get_email(get_system_managers(), None, content, subject)) diff --git a/frappe/email/smtp.py b/frappe/email/smtp.py index 0821a157a0..41c958f3e3 100644 --- a/frappe/email/smtp.py +++ b/frappe/email/smtp.py @@ -10,7 +10,7 @@ import _socket, sys from frappe.utils import cint from frappe import _ -def send(email, append_to=None): +def send(email, append_to=None, retry=1): """send the message or add it to Outbox Email""" if frappe.flags.in_test: frappe.flags.sent_mail = email.as_string() @@ -20,20 +20,30 @@ def send(email, append_to=None): frappe.msgprint(_("Emails are muted")) return - try: - smtpserver = SMTPServer(append_to=append_to) + def _send(retry): + try: + smtpserver = SMTPServer(append_to=append_to) + + # validate is called in as_string + email_body = email.as_string() + + smtpserver.sess.sendmail(email.sender, email.recipients + (email.cc or []), email_body) + except smtplib.SMTPSenderRefused: + frappe.throw(_("Invalid login or password"), title='Email Failed') + raise + except smtplib.SMTPRecipientsRefused: + frappe.msgprint(_("Invalid recipient address"), title='Email Failed') + raise + except smtplib.SMTPServerDisconnected: + if not retry: + raise + else: + retry = retry - 1 + _send(retry) - # validate is called in as_string - email_body = email.as_string() + _send(retry) - smtpserver.sess.sendmail(email.sender, email.recipients + (email.cc or []), email_body) - except smtplib.SMTPSenderRefused: - frappe.throw(_("Invalid login or password"), title='Email Failed') - raise - except smtplib.SMTPRecipientsRefused: - frappe.msgprint(_("Invalid recipient address"), title='Email Failed') - raise def get_outgoing_email_account(raise_exception_not_set=True, append_to=None): """Returns outgoing email account based on `append_to` or the default From d67a2cbc4ade97c637159c932eb855916006eb0a Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 23 Sep 2016 12:49:09 +0600 Subject: [PATCH 3/3] bumped to version 7.0.34 --- frappe/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/__init__.py b/frappe/__init__.py index 06254ebbd2..a9126b497f 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -13,7 +13,7 @@ import os, sys, importlib, inspect, json from .exceptions import * from .utils.jinja import get_jenv, get_template, render_template -__version__ = "7.0.33" +__version__ = "7.0.34" local = Local()