Browse Source

These changes allow an email to contain unicode text in the body

version-14
Anand Doshi 14 years ago
parent
commit
f4de3d3549
4 changed files with 17 additions and 13 deletions
  1. +2
    -2
      cgi-bin/webnotes/profile.py
  2. +8
    -9
      cgi-bin/webnotes/utils/email_lib/__init__.py
  3. +2
    -1
      cgi-bin/webnotes/utils/email_lib/html2text.py
  4. +5
    -1
      cgi-bin/webnotes/utils/email_lib/send.py

+ 2
- 2
cgi-bin/webnotes/profile.py View File

@@ -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


+ 8
- 9
cgi-bin/webnotes/utils/email_lib/__init__.py View File

@@ -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:


+ 2
- 1
cgi-bin/webnotes/utils/email_lib/html2text.py View File

@@ -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 = ''


+ 5
- 1
cgi-bin/webnotes/utils/email_lib/send.py View File

@@ -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…
Cancel
Save