Initialize the handler. Initialize the instance with the from and to addresses and subject line of the email. To specify a non-standard SMTP port, use the (host, port) tuple format for the mailhost argument. To specify authentication credentials, supply a (u
(self, mailhost, fromaddr, toaddrs, subject,
credentials=None, secure=None, timeout=5.0)
| 1027 | A handler class which sends an SMTP email for each logging event. |
| 1028 | """ |
| 1029 | def __init__(self, mailhost, fromaddr, toaddrs, subject, |
| 1030 | credentials=None, secure=None, timeout=5.0): |
| 1031 | """ |
| 1032 | Initialize the handler. |
| 1033 | |
| 1034 | Initialize the instance with the from and to addresses and subject |
| 1035 | line of the email. To specify a non-standard SMTP port, use the |
| 1036 | (host, port) tuple format for the mailhost argument. To specify |
| 1037 | authentication credentials, supply a (username, password) tuple |
| 1038 | for the credentials argument. To specify the use of a secure |
| 1039 | protocol (TLS), pass in a tuple for the secure argument. This will |
| 1040 | only be used when authentication credentials are supplied. The tuple |
| 1041 | will be either an empty tuple, or a single-value tuple with the name |
| 1042 | of a keyfile, or a 2-value tuple with the names of the keyfile and |
| 1043 | certificate file. (This tuple is passed to the |
| 1044 | `ssl.SSLContext.load_cert_chain` method). |
| 1045 | A timeout in seconds can be specified for the SMTP connection (the |
| 1046 | default is one second). |
| 1047 | """ |
| 1048 | logging.Handler.__init__(self) |
| 1049 | if isinstance(mailhost, (list, tuple)): |
| 1050 | self.mailhost, self.mailport = mailhost |
| 1051 | else: |
| 1052 | self.mailhost, self.mailport = mailhost, None |
| 1053 | if isinstance(credentials, (list, tuple)): |
| 1054 | self.username, self.password = credentials |
| 1055 | else: |
| 1056 | self.username = None |
| 1057 | self.fromaddr = fromaddr |
| 1058 | if isinstance(toaddrs, str): |
| 1059 | toaddrs = [toaddrs] |
| 1060 | self.toaddrs = toaddrs |
| 1061 | self.subject = subject |
| 1062 | self.secure = secure |
| 1063 | self.timeout = timeout |
| 1064 | |
| 1065 | def getSubject(self, record): |
| 1066 | """ |
no test coverage detected