def emit(self, body, **kwargs):
if not self._smtp:
self._smtp = smtplib.SMTP(self._host, self._port)
self._smtp.ehlo()
self._smtp.starttls()
self._smtp.ehlo()
subject = kwargs.pop('subject', '')
message = self._compose_message(subject, body)
# try to authenticate with the server
# before attempting to send the message
try:
self._smtp.login(self._from, self._password)
self._smtp.sendmail(self._from, self._to, message)
except smtplib.SMTPAuthenticationError:
self.logger.error('Invalid SMTP credentials for %s account'
% self._from)
finally:
self._smtp.quit()
评论列表
文章目录