Source code for webnotes.utils.email_lib
import webnotes
[docs]def sendmail_html(sender, recipients, subject, html, text=None, template=None, send_now=1, reply_to=None):
"""
Send an html mail with alternative text and using Page Templates
"""
sendmail(recipients, sender, html, subject, send_now = send_now, reply_to = reply_to, template = template)
[docs]def make_html_body(content, template = None):
"""
Generate html content from a Page Template object
"""
template_html = '%(content)s'
if template:
from webnotes.model.code import get_code
template_html = get_code(webnotes.conn.get_value('Page Template', template, 'module'), 'Page Template', template, 'html', fieldname='template')
return template_html % {'content': content}
[docs]def sendmail(recipients, sender='', msg='', subject='[No Subject]', parts=[], cc=[], attach=[], send_now=1, reply_to=None, template=None):
"""
send an html email as multipart with attachments and all
"""
from webnotes.utils.email_lib.html2text import html2text
from webnotes.utils.email_lib.send import EMail
email = EMail(sender, recipients, subject, reply_to=reply_to)
email.cc = cc
if msg:
if template:
msg = make_html_body(msg, template)
else:
# if not html, then lets put some whitespace
if (not '<br>' in msg) or (not '<p>' in msg):
msg = msg.replace('\n','<br>')
footer = get_footer()
msg = msg + (footer or '')
email.set_text(html2text(msg))
email.set_html(msg)
for p in parts:
email.set_message(p[1])
for a in attach:
email.attach(a)
email.send(send_now)