|
9 | 9 | from random import randint |
10 | 10 | from time import time, localtime |
11 | 11 |
|
| 12 | +import email |
12 | 13 | from email.message import Message |
13 | 14 | from email.utils import formatdate |
14 | 15 |
|
@@ -489,6 +490,12 @@ def emailException(self, htmlErrMsg): |
489 | 490 | Send the exception via mail, either as an attachment, |
490 | 491 | or as the body of the mail. |
491 | 492 | """ |
| 493 | + |
| 494 | + # we use quoted-printable encoding, which will automatically split long lines. |
| 495 | + # this is important because tracebacks can contain long representations of python |
| 496 | + # data, longer than the max line length smtp servers will accept (a typical limit is 990 bytes). |
| 497 | + cs = email.charset.Charset('utf-8') |
| 498 | + cs.body_encoding = email.charset.QP |
492 | 499 | message = Message() |
493 | 500 |
|
494 | 501 | # Construct the message headers |
@@ -519,19 +526,18 @@ def emailException(self, htmlErrMsg): |
519 | 526 | message.attach(part) |
520 | 527 | part = Message() |
521 | 528 | # now add htmlErrMsg |
522 | | - part.add_header('Content-Transfer-Encoding', '7bit') |
523 | 529 | part.add_header( |
524 | 530 | 'Content-Description', |
525 | 531 | 'HTML version of Webware error message') |
526 | 532 | part.add_header( |
527 | 533 | 'Content-Disposition', |
528 | 534 | 'attachment', filename='WebwareErrorMsg.html') |
529 | 535 | part.set_type('text/html') |
530 | | - part.set_payload(htmlErrMsg) |
| 536 | + part.set_payload(htmlErrMsg, charset=cs) |
531 | 537 | message.attach(part) |
532 | 538 | else: |
533 | 539 | message.set_type('text/html') |
534 | | - message.set_payload(htmlErrMsg, 'us-ascii') |
| 540 | + message.set_payload(htmlErrMsg, charset=cs) |
535 | 541 |
|
536 | 542 | # Send the message |
537 | 543 | server = self.setting('ErrorEmailServer') |
|
0 commit comments