paste smtp auth patch

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
Index: paste/exceptions/reporter.py
===================================================================
--- paste/exceptions/reporter.py (revision 6646)
+++ paste/exceptions/reporter.py (working copy)
@@ -5,6 +5,7 @@
from email.MIMEMultipart import MIMEMultipart
import smtplib
import time
+from socket import sslerror
from paste.exceptions import formatter
class Reporter(object):
@@ -35,14 +36,27 @@
to_addresses = None
from_address = None
smtp_server = 'localhost'
+ smtp_username = None
+ smtp_password = None
+ smtp_use_tls = False
subject_prefix = ''
def report(self, exc_data):
msg = self.assemble_email(exc_data)
server = smtplib.SMTP(self.smtp_server)
+ if self.smtp_use_tls:
+ server.ehlo()
+ server.starttls()
+ server.ehlo()
+ if self.smtp_username and self.smtp_password:
+ server.login(self.smtp_username, self.smtp_password)
server.sendmail(self.from_address,
self.to_addresses, msg.as_string())
- server.quit()
+ try:
+ server.quit()
+ except sslerror:
+ # sslerror is raised in tls connections on closing sometimes
+ pass
def check_params(self):
if not self.to_addresses:
Index: paste/exceptions/errormiddleware.py
===================================================================
--- paste/exceptions/errormiddleware.py (revision 6646)
+++ paste/exceptions/errormiddleware.py (working copy)
@@ -47,7 +47,8 @@
If true, then errors will be printed to ``wsgi.errors``
(frequently a server error log, or stderr).
- ``from_address``, ``smtp_server``, ``error_subject_prefix``:
+ ``from_address``, ``smtp_server``, ``error_subject_prefix``,
+ ``smtp_username``, ``smtp_password``, ``smtp_use_tls``:
variables to control the emailed exception reports
``error_message``:
@@ -85,6 +86,9 @@
show_exceptions_in_wsgi_errors=False,
from_address=None,
smtp_server=None,
+ smtp_username=None,
+ smtp_password=None,
+ smtp_use_tls=False,
error_subject_prefix=None,
error_message=None,
xmlhttp_key=None):
@@ -111,6 +115,9 @@
if smtp_server is None:
smtp_server = global_conf.get('smtp_server', 'localhost')
self.smtp_server = smtp_server
+ self.smtp_username = smtp_username or global_conf.get('smtp_username')
+ self.smtp_password = smtp_password or global_conf.get('smtp_password')
+ self.smtp_use_tls = smtp_use_tls or converters.asbool(global_conf.get('smtp_use_tls'))
self.error_subject_prefix = error_subject_prefix or ''
if error_message is None:
error_message = global_conf.get('error_message')
@@ -171,6 +178,9 @@
show_exceptions_in_wsgi_errors=self.show_exceptions_in_wsgi_errors,
error_email_from=self.from_address,
smtp_server=self.smtp_server,
+ smtp_username=self.smtp_username,
+ smtp_password=self.smtp_password,
+ smtp_use_tls=self.smtp_use_tls,
error_subject_prefix=self.error_subject_prefix,
error_message=self.error_message,
simple_html_error=simple_html_error)
@@ -294,6 +304,9 @@
show_exceptions_in_wsgi_errors=False,
error_email_from='errors@localhost',
smtp_server='localhost',
+ smtp_username=None,
+ smtp_password=None,
+ smtp_use_tls=False,
error_subject_prefix='',
error_message=None,
simple_html_error=False,
@@ -324,6 +337,9 @@
to_addresses=error_email,
from_address=error_email_from,
smtp_server=smtp_server,
+ smtp_username=smtp_username,
+ smtp_password=smtp_password,
+ smtp_use_tls=smtp_use_tls,
subject_prefix=error_subject_prefix)
rep_err = send_report(rep, exc_data, html=html)
if rep_err: