email in utf-8
This commit is contained in:
parent
20de5a21c3
commit
dfcd05e166
4 changed files with 17 additions and 13 deletions
|
|
@ -162,12 +162,12 @@ class Profile:
|
|||
|
||||
# update tab Profile
|
||||
webnotes.conn.sql("UPDATE tabProfile SET password=password(%s) WHERE name=%s", (pwd, profile[0][0]))
|
||||
|
||||
|
||||
self.send_email("Password Reset", "<p>Dear %s%s,</p><p>your password has been changed to %s</p><p>[Automatically Generated]</p>" % (profile[0][2], (profile[0][3] and (' ' + profile[0][3]) or ''), pwd), profile[0][1])
|
||||
|
||||
def send_email(self, subj, mess, email):
|
||||
import webnotes.utils.email_lib
|
||||
|
||||
|
||||
webnotes.utils.email_lib.sendmail(email, msg=mess, subject=subj)
|
||||
|
||||
# update recent documents
|
||||
|
|
|
|||
|
|
@ -29,19 +29,18 @@ def sendmail(recipients, sender='', msg='', subject='[No Subject]', parts=[], cc
|
|||
|
||||
email = EMail(sender, recipients, subject, reply_to=reply_to)
|
||||
email.cc = cc
|
||||
|
||||
if msg:
|
||||
if template:
|
||||
msg = make_html_body(msg, template)
|
||||
|
||||
if msg:
|
||||
if template:
|
||||
msg = make_html_body(msg, template).encode('utf-8')
|
||||
else:
|
||||
# if not html, then lets put some whitespace
|
||||
if (not '<br>' in msg) or (not '<p>' in msg):
|
||||
msg = msg.replace('\n','<br>')
|
||||
|
||||
msg = msg.replace('\n','<br>')
|
||||
footer = get_footer()
|
||||
msg = msg + (footer or '')
|
||||
email.set_text(html2text(msg))
|
||||
email.set_html(msg)
|
||||
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:
|
||||
|
|
|
|||
|
|
@ -447,7 +447,8 @@ def html2text_file(html, out=wrapwrite, baseurl=''):
|
|||
return h.close()
|
||||
|
||||
def html2text(html, baseurl=''):
|
||||
return optwrap(html2text_file(html, None, baseurl))
|
||||
txt = html2text_file(html.decode('utf-8'), None, baseurl)
|
||||
return optwrap(txt.encode('utf-8'))
|
||||
|
||||
if __name__ == "__main__":
|
||||
baseurl = ''
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@ class EMail:
|
|||
"""
|
||||
def __init__(self, sender='', recipients=[], subject='', from_defs=0, alternative=0, reply_to=None):
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from email import Charset
|
||||
Charset.add_charset('utf-8', Charset.QP, Charset.QP, 'utf-8')
|
||||
|
||||
if type(recipients)==str:
|
||||
recipients = recipients.replace(';', ',')
|
||||
recipients = recipients.split(',')
|
||||
|
|
@ -36,7 +39,8 @@ class EMail:
|
|||
Attach message in the text portion of multipart/alternative
|
||||
"""
|
||||
from email.mime.text import MIMEText
|
||||
part = MIMEText(message, 'plain')
|
||||
msg = unicode(message, 'utf-8')
|
||||
part = MIMEText(msg.encode('utf-8'), 'plain', 'UTF-8')
|
||||
self.msg_multipart.attach(part)
|
||||
|
||||
def set_html(self, message):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue