def send(self, address, alert, language='en'):
message = self.get_message(alert, language, 'email')
# Extract the subject
subject = message.splitlines(1)[0].lstrip('Subject:').strip()
# Remove the subject line
message = '\n'.join(message.splitlines()[1:])
headers = {
'X-NAV-alert-netbox': alert.netbox,
'X-NAV-alert-device': alert.device,
'X-NAV-alert-subsystem': alert.source,
}
try:
if not address.DEBUG_MODE:
email = EmailMessage(subject=subject, body=message,
to=[address.address])
email.send(fail_silently=False)
else:
_logger.debug('alert %d: In testing mode, would have sent '
'email to %s', alert.id, address.address)
except SMTPException as err:
msg = 'Could not send email: %s" ' % err
if (isinstance(err, SMTPRecipientsRefused) or
(hasattr(err, "smtp_code") and
str(err.smtp_code).startswith('5'))):
raise FatalDispatcherException(msg)
# Reraise as DispatcherException so that we can catch it further up
raise DispatcherException(msg)
评论列表
文章目录