Emit a record. Format the record and send it to the specified addressees.
(self, record)
| 1079 | return self.subject |
| 1080 | |
| 1081 | def emit(self, record): |
| 1082 | """ |
| 1083 | Emit a record. |
| 1084 | |
| 1085 | Format the record and send it to the specified addressees. |
| 1086 | """ |
| 1087 | try: |
| 1088 | import smtplib |
| 1089 | from email.message import EmailMessage |
| 1090 | import email.utils |
| 1091 | |
| 1092 | port = self.mailport |
| 1093 | if not port: |
| 1094 | port = smtplib.SMTP_PORT |
| 1095 | smtp = smtplib.SMTP(self.mailhost, port, timeout=self.timeout) |
| 1096 | msg = EmailMessage() |
| 1097 | msg['From'] = self.fromaddr |
| 1098 | msg['To'] = ','.join(self.toaddrs) |
| 1099 | msg['Subject'] = self.getSubject(record) |
| 1100 | msg['Date'] = email.utils.localtime() |
| 1101 | msg.set_content(self.format(record)) |
| 1102 | if self.username: |
| 1103 | if self.secure is not None: |
| 1104 | import ssl |
| 1105 | |
| 1106 | try: |
| 1107 | keyfile = self.secure[0] |
| 1108 | except IndexError: |
| 1109 | keyfile = None |
| 1110 | |
| 1111 | try: |
| 1112 | certfile = self.secure[1] |
| 1113 | except IndexError: |
| 1114 | certfile = None |
| 1115 | |
| 1116 | context = ssl._create_stdlib_context( |
| 1117 | certfile=certfile, keyfile=keyfile |
| 1118 | ) |
| 1119 | smtp.ehlo() |
| 1120 | smtp.starttls(context=context) |
| 1121 | smtp.ehlo() |
| 1122 | smtp.login(self.username, self.password) |
| 1123 | smtp.send_message(msg) |
| 1124 | smtp.quit() |
| 1125 | except Exception: |
| 1126 | self.handleError(record) |
| 1127 | |
| 1128 | class NTEventLogHandler(logging.Handler): |
| 1129 | """ |
no test coverage detected