+

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

Benjamin Renard [2012-04-20 14:47:54]
MantisMail.send() : fix encoding problems and log error on problem
Filename
src/usr/share/mantis-smtp/MantisMail.py
diff --git a/src/usr/share/mantis-smtp/MantisMail.py b/src/usr/share/mantis-smtp/MantisMail.py
index e66bc48..531ae5d 100755
--- a/src/usr/share/mantis-smtp/MantisMail.py
+++ b/src/usr/share/mantis-smtp/MantisMail.py
@@ -96,17 +96,17 @@ class MantisMail(object):
 		return self.decode(s[0],prefer_encoding=s[1])

 def send(mail_from,to,subject,content,smtp_host='127.0.0.1',smtp_port=25):
-	msg = MIMEText(content)
+	msg = MIMEText(content,'plain','iso-8859-1')
 	msg['To'] = to
 	msg['From'] = mail_from
-	msg['Subject'] = subject
+	msg['Subject'] = email.header.make_header([(subject,'iso-8859-1')])

 	server = smtplib.SMTP(smtp_host,smtp_port)

 	try:
 		server.sendmail(mail_from, [to], msg.as_string())
-	except:
-		logging.error('Error sending mail to %s - %s : %s' % (to,subject,sys.exc_info()[0]))
+	except Exception, e:
+		logging.error('Error sending mail to %s - %s : %s - %s' % (to,subject,sys.exc_info()[0],e))
                 return

 class MantisMailError(Exception):
ViewGit