[refactor] frappe.utils.email_lib > frappe.email
This commit is contained in:
parent
d9dfbc02d9
commit
7dd7944590
18 changed files with 67 additions and 67 deletions
|
|
@ -228,18 +228,18 @@ def sendmail(recipients=(), sender="", subject="No Subject", message="No Message
|
|||
add_unsubscribe_link=False, attachments=None):
|
||||
|
||||
if bulk:
|
||||
import frappe.utils.email_lib.bulk
|
||||
frappe.utils.email_lib.bulk.send(recipients=recipients, sender=sender,
|
||||
import frappe.email.bulk
|
||||
frappe.email.bulk.send(recipients=recipients, sender=sender,
|
||||
subject=subject, message=message, ref_doctype = ref_doctype,
|
||||
ref_docname = ref_docname, add_unsubscribe_link=add_unsubscribe_link, attachments=attachments)
|
||||
|
||||
else:
|
||||
import frappe.utils.email_lib
|
||||
import frappe.email
|
||||
if as_markdown:
|
||||
frappe.utils.email_lib.sendmail_md(recipients, sender=sender,
|
||||
frappe.email.sendmail_md(recipients, sender=sender,
|
||||
subject=subject, msg=message, attachments=attachments)
|
||||
else:
|
||||
frappe.utils.email_lib.sendmail(recipients, sender=sender,
|
||||
frappe.email.sendmail(recipients, sender=sender,
|
||||
subject=subject, msg=message, attachments=attachments)
|
||||
|
||||
logger = None
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ import urllib
|
|||
from email.utils import formataddr
|
||||
from frappe.website.utils import is_signup_enabled
|
||||
from frappe.utils import get_url, cstr
|
||||
from frappe.utils.email_lib.email_body import get_email
|
||||
from frappe.utils.email_lib.smtp import send
|
||||
from frappe.email.email_body import get_email
|
||||
from frappe.email.smtp import send
|
||||
from frappe.utils import scrub_urls, cint
|
||||
from frappe import _
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ def send_event_digest():
|
|||
text += '<p style="color: #888; font-size: 80%; margin-top: 20px; padding-top: 10px; border-top: 1px solid #eee;">'\
|
||||
+ frappe._("Daily Event Digest is sent for Calendar Events where reminders are set.")+'</p>'
|
||||
|
||||
from frappe.utils.email_lib import sendmail
|
||||
from frappe.email import sendmail
|
||||
sendmail(recipients=user.email, subject=frappe._("Upcoming Events for Today"),
|
||||
msg = text)
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
|
||||
# MIT License. See license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
|
||||
from frappe.email.email_body import get_email
|
||||
from frappe.email.smtp import send
|
||||
|
||||
def sendmail_md(recipients, sender=None, msg=None, subject=None, attachments=None):
|
||||
"""send markdown email"""
|
||||
import markdown2
|
||||
sendmail(recipients, sender, markdown2.markdown(msg), subject, attachments)
|
||||
|
||||
def sendmail(recipients, sender='', msg='', subject='[No Subject]', attachments=None):
|
||||
"""send an html email as multipart with attachments and all"""
|
||||
send(get_email(recipients, sender, msg, subject, attachments=attachments))
|
||||
|
||||
def sendmail_to_system_managers(subject, content):
|
||||
send(get_email(get_system_managers(), None, content, subject))
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_contact_list():
|
||||
"""Returns contacts (from autosuggest)"""
|
||||
cond = ['`%s` like "%s%%"' % (f,
|
||||
frappe.form_dict.get('txt')) for f in frappe.form_dict.get('where').split(',')]
|
||||
cl = frappe.db.sql("select `%s` from `tab%s` where %s" % (
|
||||
frappe.form_dict.get('select')
|
||||
,frappe.form_dict.get('from')
|
||||
,' OR '.join(cond)
|
||||
)
|
||||
)
|
||||
frappe.response['cl'] = filter(None, [c[0] for c in cl])
|
||||
|
||||
def get_system_managers():
|
||||
return frappe.db.sql_list("""select parent FROM tabUserRole
|
||||
WHERE role='System Manager'
|
||||
AND parent!='Administrator'
|
||||
AND parent IN
|
||||
(SELECT email FROM tabUser WHERE enabled=1)""")
|
||||
|
|
@ -6,9 +6,9 @@ import frappe
|
|||
import HTMLParser
|
||||
import urllib
|
||||
from frappe import msgprint, throw, _
|
||||
from frappe.utils.email_lib.smtp import SMTPServer
|
||||
from frappe.utils.email_lib.email_body import get_email, get_formatted_html
|
||||
from frappe.utils.email_lib.html2text import html2text
|
||||
from frappe.email.smtp import SMTPServer
|
||||
from frappe.email.email_body import get_email, get_formatted_html
|
||||
from frappe.email.html2text import html2text
|
||||
from frappe.utils import cint, get_url, nowdate
|
||||
|
||||
class BulkLimitCrossedError(frappe.ValidationError): pass
|
||||
|
|
@ -45,7 +45,7 @@ def send(recipients=None, sender=None, doctype='User', email_field='email',
|
|||
<small><a href="%s/?%s">
|
||||
Unsubscribe</a> from this list.</small></div>""" % (get_url(),
|
||||
urllib.urlencode({
|
||||
"cmd": "frappe.utils.email_lib.bulk.unsubscribe",
|
||||
"cmd": "frappe.email.bulk.unsubscribe",
|
||||
"email": doc.get(email_field),
|
||||
"type": doctype,
|
||||
"email_field": email_field
|
||||
|
|
@ -17,7 +17,7 @@ class OutgoingEmailSettings(Document):
|
|||
|
||||
if self.mail_server and not frappe.local.flags.in_patch:
|
||||
from frappe.utils import cint
|
||||
from frappe.utils.email_lib.smtp import SMTPServer
|
||||
from frappe.email.smtp import SMTPServer
|
||||
smtpserver = SMTPServer(login = self.mail_login,
|
||||
password = self.mail_password,
|
||||
server = self.mail_server,
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ class EMail:
|
|||
def set_html_as_text(self, html):
|
||||
"""return html2text"""
|
||||
import HTMLParser
|
||||
from frappe.utils.email_lib.html2text import html2text
|
||||
from frappe.email.html2text import html2text
|
||||
try:
|
||||
self.set_text(html2text(html))
|
||||
except HTMLParser.HTMLParseError:
|
||||
|
|
@ -71,9 +71,9 @@ doc_events = {
|
|||
}
|
||||
|
||||
scheduler_events = {
|
||||
"all": ["frappe.utils.email_lib.bulk.flush"],
|
||||
"all": ["frappe.email.bulk.flush"],
|
||||
"daily": [
|
||||
"frappe.utils.email_lib.bulk.clear_outbox",
|
||||
"frappe.email.bulk.clear_outbox",
|
||||
"frappe.core.doctype.notification_count.notification_count.clear_notifications",
|
||||
"frappe.core.doctype.event.event.send_event_digest",
|
||||
"frappe.sessions.clear_expired_sessions",
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ def add_comment(args=None):
|
|||
recipients = list(set(commentors if owner=="Administrator" else (commentors + [owner])))
|
||||
|
||||
|
||||
from frappe.utils.email_lib.bulk import send
|
||||
from frappe.email.bulk import send
|
||||
send(recipients=recipients,
|
||||
doctype='Comment',
|
||||
email_field='comment_by',
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ def send_message(subject="Website Query", message="", sender=""):
|
|||
# send email
|
||||
forward_to_email = frappe.db.get_value("Contact Us Settings", None, "forward_to_email")
|
||||
if forward_to_email:
|
||||
from frappe.utils.email_lib import sendmail
|
||||
from frappe.email import sendmail
|
||||
sendmail(forward_to_email, sender, message, subject)
|
||||
|
||||
return "okay"
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe.website.permissions import get_access
|
||||
from frappe.utils.email_lib.bulk import send
|
||||
from frappe.email.bulk import send
|
||||
|
||||
@frappe.whitelist()
|
||||
def suggest_user(term, group):
|
||||
|
|
|
|||
|
|
@ -15,11 +15,11 @@ class TestEmail(unittest.TestCase):
|
|||
frappe.db.sql("""delete from `tabBulk Email`""")
|
||||
|
||||
def test_send(self):
|
||||
from frappe.utils.email_lib import sendmail
|
||||
from frappe.email import sendmail
|
||||
#sendmail('test@example.com', subject='Test Mail', msg="Test Content")
|
||||
|
||||
def test_bulk(self):
|
||||
from frappe.utils.email_lib.bulk import send
|
||||
from frappe.email.bulk import send
|
||||
send(recipients = ['test@example.com', 'test1@example.com'],
|
||||
sender="admin@example.com",
|
||||
doctype='User', email_field='email',
|
||||
|
|
@ -33,7 +33,7 @@ class TestEmail(unittest.TestCase):
|
|||
|
||||
def test_flush(self):
|
||||
self.test_bulk()
|
||||
from frappe.utils.email_lib.bulk import flush
|
||||
from frappe.email.bulk import flush
|
||||
flush(from_test=True)
|
||||
bulk = frappe.db.sql("""select * from `tabBulk Email` where status='Sent'""", as_dict=1)
|
||||
self.assertEquals(len(bulk), 2)
|
||||
|
|
@ -41,7 +41,7 @@ class TestEmail(unittest.TestCase):
|
|||
self.assertTrue('test1@example.com' in [d['recipient'] for d in bulk])
|
||||
|
||||
def test_unsubscribe(self):
|
||||
from frappe.utils.email_lib.bulk import unsubscribe, send
|
||||
from frappe.email.bulk import unsubscribe, send
|
||||
frappe.local.form_dict = frappe._dict({
|
||||
'email':'test@example.com',
|
||||
'type':'User',
|
||||
|
|
@ -63,7 +63,7 @@ class TestEmail(unittest.TestCase):
|
|||
self.assertTrue('Unsubscribe' in bulk[0]['message'])
|
||||
|
||||
def test_bulk_limit(self):
|
||||
from frappe.utils.email_lib.bulk import unsubscribe, send, BulkLimitCrossedError
|
||||
from frappe.email.bulk import unsubscribe, send, BulkLimitCrossedError
|
||||
self.assertRaises(BulkLimitCrossedError, send,
|
||||
recipients=['test@example.com']*1000,
|
||||
sender="admin@example.com",
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ class BackupGenerator:
|
|||
"""
|
||||
Sends the link to backup file located at erpnext/backups
|
||||
"""
|
||||
from frappe.utils.email_lib import sendmail, get_system_managers
|
||||
from frappe.email import sendmail, get_system_managers
|
||||
|
||||
recipient_list = get_system_managers()
|
||||
db_backup_url = get_url(os.path.join('backups', os.path.basename(self.backup_path_db)))
|
||||
|
|
|
|||
|
|
@ -1,40 +0,0 @@
|
|||
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
|
||||
# MIT License. See license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
|
||||
from frappe.utils.email_lib.email_body import get_email
|
||||
from frappe.utils.email_lib.smtp import send
|
||||
|
||||
def sendmail_md(recipients, sender=None, msg=None, subject=None, attachments=None):
|
||||
"""send markdown email"""
|
||||
import markdown2
|
||||
sendmail(recipients, sender, markdown2.markdown(msg), subject, attachments)
|
||||
|
||||
def sendmail(recipients, sender='', msg='', subject='[No Subject]', attachments=None):
|
||||
"""send an html email as multipart with attachments and all"""
|
||||
send(get_email(recipients, sender, msg, subject, attachments=attachments))
|
||||
|
||||
def sendmail_to_system_managers(subject, content):
|
||||
send(get_email(get_system_managers(), None, content, subject))
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_contact_list():
|
||||
"""Returns contacts (from autosuggest)"""
|
||||
cond = ['`%s` like "%s%%"' % (f,
|
||||
frappe.form_dict.get('txt')) for f in frappe.form_dict.get('where').split(',')]
|
||||
cl = frappe.db.sql("select `%s` from `tab%s` where %s" % (
|
||||
frappe.form_dict.get('select')
|
||||
,frappe.form_dict.get('from')
|
||||
,' OR '.join(cond)
|
||||
)
|
||||
)
|
||||
frappe.response['cl'] = filter(None, [c[0] for c in cl])
|
||||
|
||||
def get_system_managers():
|
||||
return frappe.db.sql_list("""select parent FROM tabUserRole
|
||||
WHERE role='System Manager'
|
||||
AND parent!='Administrator'
|
||||
AND parent IN
|
||||
(SELECT email FROM tabUser WHERE enabled=1)""")
|
||||
|
|
@ -8,8 +8,8 @@ from __future__ import unicode_literals
|
|||
import frappe
|
||||
from frappe import _
|
||||
from frappe.utils import get_fullname
|
||||
from frappe.utils.email_lib.bulk import send
|
||||
from frappe.utils.email_lib import sendmail
|
||||
from frappe.email.bulk import send
|
||||
from frappe.email import sendmail
|
||||
|
||||
from frappe.model.document import Document
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue