[refactor] used frappe.sendmail

This commit is contained in:
Rushabh Mehta 2014-09-16 14:57:31 +05:30
parent 5cdc8e560c
commit bf8715dba4
4 changed files with 16 additions and 21 deletions

View File

@ -185,12 +185,10 @@ class SalarySlip(TransactionBase):
def send_mail_funct(self):
from frappe.email import sendmail
receiver = frappe.db.get_value("Employee", self.employee, "company_email")
if receiver:
subj = 'Salary Slip - ' + cstr(self.month) +'/'+cstr(self.fiscal_year)
sendmail([receiver], subject=subj, msg = _("Please see attachment"),
frappe.sendmail([receiver], subject=subj, msg = _("Please see attachment"),
attachments=[{
"fname": self.name + ".pdf",
"fcontent": frappe.get_print_format(self.doctype, self.name, as_pdf = True)

View File

@ -21,10 +21,10 @@ def take_backups_weekly():
def take_backups_if(freq):
if frappe.db.get_value("Backup Manager", None, "upload_backups_to_dropbox")==freq:
take_backups_dropbox()
# if frappe.db.get_value("Backup Manager", None, "upload_backups_to_gdrive")==freq:
# take_backups_gdrive()
@frappe.whitelist()
def take_backups_dropbox():
did_not_upload, error_log = [], []
@ -32,7 +32,7 @@ def take_backups_dropbox():
from erpnext.setup.doctype.backup_manager.backup_dropbox import backup_to_dropbox
did_not_upload, error_log = backup_to_dropbox()
if did_not_upload: raise Exception
send_email(True, "Dropbox")
except Exception:
file_and_error = [" - ".join(f) for f in zip(did_not_upload, error_log)]
@ -40,7 +40,7 @@ def take_backups_dropbox():
frappe.errprint(error_message)
send_email(False, "Dropbox", error_message)
#backup to gdrive
#backup to gdrive
@frappe.whitelist()
def take_backups_gdrive():
did_not_upload, error_log = [], []
@ -48,7 +48,7 @@ def take_backups_gdrive():
from erpnext.setup.doctype.backup_manager.backup_googledrive import backup_to_gdrive
did_not_upload, error_log = backup_to_gdrive()
if did_not_upload: raise Exception
send_email(True, "Google Drive")
except Exception:
file_and_error = [" - ".join(f) for f in zip(did_not_upload, error_log)]
@ -57,10 +57,9 @@ def take_backups_gdrive():
send_email(False, "Google Drive", error_message)
def send_email(success, service_name, error_status=None):
from frappe.email import sendmail
if success:
subject = "Backup Upload Successful"
message ="""<h3>Backup Uploaded Successfully</h3><p>Hi there, this is just to inform you
message ="""<h3>Backup Uploaded Successfully</h3><p>Hi there, this is just to inform you
that your backup was successfully uploaded to your %s account. So relax!</p>
""" % service_name
@ -71,9 +70,9 @@ def send_email(success, service_name, error_status=None):
<p>Error message: %s</p>
<p>Please contact your system manager for more information.</p>
""" % (service_name, error_status)
if not frappe.db:
frappe.connect()
recipients = frappe.db.get_value("Backup Manager", None, "send_notifications_to").split(",")
sendmail(recipients, subject=subject, msg=message)
frappe.sendmail(recipients=recipients, subject=subject, msg=message)

View File

@ -9,7 +9,6 @@ from frappe.utils import fmt_money, formatdate, now_datetime, cstr, esc, \
from frappe.utils.dateutils import datetime_in_user_format
from datetime import timedelta
from dateutil.relativedelta import relativedelta
from frappe.email import sendmail
from frappe.core.doctype.user.user import STANDARD_USERS
content_sequence = [
@ -83,10 +82,10 @@ class EmailDigest(Document):
msg_for_this_receipient = self.get_msg_html(self.get_user_specific_content(user_id) + \
common_msg)
if msg_for_this_receipient:
sendmail(recipients=user_id,
frappe.sendmail(recipients=user_id,
subject="[ERPNext] [{frequency} Digest] {name}".format(
frequency=self.frequency, name=self.name),
msg=msg_for_this_receipient)
msg=msg_for_this_receipient, bulk=True)
def get_digest_msg(self):
return self.get_msg_html(self.get_user_specific_content(frappe.session.user) + \

View File

@ -6,7 +6,6 @@ from frappe import _
import json
from frappe.utils import flt, cstr, nowdate, add_days, cint
from frappe.defaults import get_global_default
from frappe.email import sendmail
from erpnext.accounts.utils import get_fiscal_year, FiscalYearError
class InvalidWarehouseCompany(frappe.ValidationError): pass
@ -336,11 +335,11 @@ def send_email_notification(mr_list):
msg += "<tr><td>" + item.item_code + "</td><td>" + item.warehouse + "</td><td>" + \
cstr(item.qty) + "</td><td>" + cstr(item.uom) + "</td></tr>"
msg += "</table>"
sendmail(email_list, subject='Auto Material Request Generation Notification', msg = msg)
frappe.sendmail(recipients=email_list, subject='Auto Material Request Generation Notification', msg = msg)
def notify_errors(exceptions_list):
subject = "[Important] [ERPNext] Error(s) while creating Material Requests based on Re-order Levels"
msg = """Dear System Manager,
content = """Dear System Manager,
An error occured for certain Items while creating Material Requests based on Re-order level.
@ -353,5 +352,5 @@ Please rectify these issues:
Regards,
Administrator""" % ("\n\n".join(exceptions_list),)
from frappe.utils.user import get_system_managers
sendmail(get_system_managers(), subject=subject, msg=msg)
from frappe.email import sendmail_to_system_managers
sendmail_to_system_managers(subject, content)