@@ -360,7 +360,7 @@ def sendmail(recipients=(), sender="", subject="No Subject", message="No Message | |||||
unsubscribe_method=None, unsubscribe_params=None, unsubscribe_message=None, | unsubscribe_method=None, unsubscribe_params=None, unsubscribe_message=None, | ||||
attachments=None, content=None, doctype=None, name=None, reply_to=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, | 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**. | """Send email using user's default **Email Account** or global default **Email Account**. | ||||
@@ -397,11 +397,11 @@ def sendmail(recipients=(), sender="", subject="No Subject", message="No Message | |||||
if as_markdown: | if as_markdown: | ||||
frappe.email.sendmail_md(recipients, sender=sender, | frappe.email.sendmail_md(recipients, sender=sender, | ||||
subject=subject, msg=content or message, attachments=attachments, reply_to=reply_to, | 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: | else: | ||||
frappe.email.sendmail(recipients, sender=sender, | frappe.email.sendmail(recipients, sender=sender, | ||||
subject=subject, msg=content or message, attachments=attachments, reply_to=reply_to, | 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 = [] | whitelisted = [] | ||||
guest_methods = [] | guest_methods = [] | ||||
@@ -209,9 +209,11 @@ class User(Document): | |||||
from frappe.utils import get_url | from frappe.utils import get_url | ||||
link = self.reset_password() | link = self.reset_password() | ||||
self.send_login_mail(_("Verify Your Account"), "templates/emails/new_user.html", | self.send_login_mail(_("Verify Your Account"), "templates/emails/new_user.html", | ||||
{"link": link, "site_url": get_url()}) | {"link": link, "site_url": get_url()}) | ||||
def send_login_mail(self, subject, template, add_args, now=None): | def send_login_mail(self, subject, template, add_args, now=None): | ||||
"""send mail with login details""" | """send mail with login details""" | ||||
from frappe.utils.user import get_user_fullname | from frappe.utils.user import get_user_fullname | ||||
@@ -238,7 +240,7 @@ class User(Document): | |||||
frappe.sendmail(recipients=self.email, sender=sender, subject=subject, | frappe.sendmail(recipients=self.email, sender=sender, subject=subject, | ||||
message=frappe.get_template(template).render(args), | 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): | def a_system_manager_should_exist(self): | ||||
if not self.get_other_system_managers(): | if not self.get_other_system_managers(): | ||||
@@ -9,20 +9,22 @@ from frappe.email.smtp import send | |||||
from frappe.utils import markdown | from frappe.utils import markdown | ||||
def sendmail_md(recipients, sender=None, msg=None, subject=None, attachments=None, content=None, | 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""" | """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, | 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""" | """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: | if message_id: | ||||
mail.set_message_id(message_id) | mail.set_message_id(message_id) | ||||
if in_reply_to: | if in_reply_to: | ||||
mail.set_in_reply_to(in_reply_to) | mail.set_in_reply_to(in_reply_to) | ||||
send(mail) | |||||
send(mail, retry=retry) | |||||
def sendmail_to_system_managers(subject, content): | def sendmail_to_system_managers(subject, content): | ||||
send(get_email(get_system_managers(), None, content, subject)) | send(get_email(get_system_managers(), None, content, subject)) | ||||
@@ -10,7 +10,7 @@ import _socket, sys | |||||
from frappe.utils import cint | from frappe.utils import cint | ||||
from frappe import _ | 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""" | """send the message or add it to Outbox Email""" | ||||
if frappe.flags.in_test: | if frappe.flags.in_test: | ||||
frappe.flags.sent_mail = email.as_string() | frappe.flags.sent_mail = email.as_string() | ||||
@@ -20,20 +20,30 @@ def send(email, append_to=None): | |||||
frappe.msgprint(_("Emails are muted")) | frappe.msgprint(_("Emails are muted")) | ||||
return | 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): | def get_outgoing_email_account(raise_exception_not_set=True, append_to=None): | ||||
"""Returns outgoing email account based on `append_to` or the default | """Returns outgoing email account based on `append_to` or the default | ||||
@@ -166,7 +166,7 @@ def scheduled_backup(older_than=6, ignore_files=False, backup_path_db=None, back | |||||
return odb | 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): | 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,\ | odb = BackupGenerator(frappe.conf.db_name, frappe.conf.db_name,\ | ||||
frappe.conf.db_password, | frappe.conf.db_password, | ||||
backup_path_db=backup_path_db, backup_path_files=backup_path_files, | backup_path_db=backup_path_db, backup_path_files=backup_path_files, | ||||