MantisMail.send() : fix encoding problems and log error on problem
Benjamin Renard

Benjamin Renard commited on 2012-04-20 14:49:15
Showing 1 changed files, with 4 additions and 4 deletions.

... ...
@@ -96,17 +96,17 @@ class MantisMail(object):
96 96
 		return self.decode(s[0],prefer_encoding=s[1])
97 97
 
98 98
 def send(mail_from,to,subject,content,smtp_host='127.0.0.1',smtp_port=25):
99
-	msg = MIMEText(content)
99
+	msg = MIMEText(content,'plain','iso-8859-1')
100 100
 	msg['To'] = to
101 101
 	msg['From'] = mail_from
102
-	msg['Subject'] = subject
102
+	msg['Subject'] = email.header.make_header([(subject,'iso-8859-1')])
103 103
 
104 104
 	server = smtplib.SMTP(smtp_host,smtp_port)
105 105
 
106 106
 	try:
107 107
 		server.sendmail(mail_from, [to], msg.as_string())
108
-	except:
109
-		logging.error('Error sending mail to %s - %s : %s' % (to,subject,sys.exc_info()[0]))
108
+	except Exception, e:
109
+		logging.error('Error sending mail to %s - %s : %s - %s' % (to,subject,sys.exc_info()[0],e))
110 110
                 return
111 111
 
112 112
 class MantisMailError(Exception):
113 113