@@ -162,12 +162,12 @@ class Profile: | |||||
# update tab Profile | # update tab Profile | ||||
webnotes.conn.sql("UPDATE tabProfile SET password=password(%s) WHERE name=%s", (pwd, profile[0][0])) | 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]) | 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): | def send_email(self, subj, mess, email): | ||||
import webnotes.utils.email_lib | import webnotes.utils.email_lib | ||||
webnotes.utils.email_lib.sendmail(email, msg=mess, subject=subj) | webnotes.utils.email_lib.sendmail(email, msg=mess, subject=subj) | ||||
# update recent documents | # 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 = EMail(sender, recipients, subject, reply_to=reply_to) | ||||
email.cc = cc | 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: | else: | ||||
# if not html, then lets put some whitespace | # if not html, then lets put some whitespace | ||||
if (not '<br>' in msg) or (not '<p>' in msg): | if (not '<br>' in msg) or (not '<p>' in msg): | ||||
msg = msg.replace('\n','<br>') | |||||
msg = msg.replace('\n','<br>') | |||||
footer = get_footer() | 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: | for p in parts: | ||||
email.set_message(p[1]) | email.set_message(p[1]) | ||||
for a in attach: | for a in attach: | ||||
@@ -447,7 +447,8 @@ def html2text_file(html, out=wrapwrite, baseurl=''): | |||||
return h.close() | return h.close() | ||||
def html2text(html, baseurl=''): | 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__": | if __name__ == "__main__": | ||||
baseurl = '' | baseurl = '' | ||||
@@ -16,6 +16,9 @@ class EMail: | |||||
""" | """ | ||||
def __init__(self, sender='', recipients=[], subject='', from_defs=0, alternative=0, reply_to=None): | def __init__(self, sender='', recipients=[], subject='', from_defs=0, alternative=0, reply_to=None): | ||||
from email.mime.multipart import MIMEMultipart | 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: | if type(recipients)==str: | ||||
recipients = recipients.replace(';', ',') | recipients = recipients.replace(';', ',') | ||||
recipients = recipients.split(',') | recipients = recipients.split(',') | ||||
@@ -36,7 +39,8 @@ class EMail: | |||||
Attach message in the text portion of multipart/alternative | Attach message in the text portion of multipart/alternative | ||||
""" | """ | ||||
from email.mime.text import MIMEText | 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) | self.msg_multipart.attach(part) | ||||
def set_html(self, message): | def set_html(self, message): | ||||