Emit a record. Format the record and send it to the specified addressees.
(self, record)
| 1059 | return self.subject |
| 1060 | |
| 1061 | def emit(self, record): |
| 1062 | """ |
| 1063 | Emit a record. |
| 1064 | |
| 1065 | Format the record and send it to the specified addressees. |
| 1066 | """ |
| 1067 | try: |
| 1068 | import smtplib |
| 1069 | from email.message import EmailMessage |
| 1070 | import email.utils |
| 1071 | |
| 1072 | port = self.mailport |
| 1073 | if not port: |
| 1074 | port = smtplib.SMTP_PORT |
| 1075 | smtp = smtplib.SMTP(self.mailhost, port, timeout=self.timeout) |
| 1076 | msg = EmailMessage() |
| 1077 | msg['From'] = self.fromaddr |
| 1078 | msg['To'] = ','.join(self.toaddrs) |
| 1079 | msg['Subject'] = self.getSubject(record) |
| 1080 | msg['Date'] = email.utils.localtime() |
| 1081 | msg.set_content(self.format(record)) |
| 1082 | if self.username: |
| 1083 | if self.secure is not None: |
| 1084 | smtp.ehlo() |
| 1085 | smtp.starttls(*self.secure) |
| 1086 | smtp.ehlo() |
| 1087 | smtp.login(self.username, self.password) |
| 1088 | smtp.send_message(msg) |
| 1089 | smtp.quit() |
| 1090 | except Exception: |
| 1091 | self.handleError(record) |
| 1092 | |
| 1093 | class NTEventLogHandler(logging.Handler): |
| 1094 | """ |
no test coverage detected