More flexibility in email alert template (MIME, etc)
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Network Administration Visualized |
New
|
Undecided
|
Unassigned |
Bug Description
Alert mail sent by NAV is MIME-type text/plain. It would be useful to also allow HTML-formatted mail, preferably as an alternative to text-formatting, aka multipart/
One possibility is to consider the mail template as a RFC822-formatted message, containing both headers and body, separated by a blank line. The Django templating system makes this a bit cumbersome, because the handling of white-space and linefeeds is geared towards HTML-output.
In the current implementation, the Subject header must be the first line. A simplistic solution to the more general approach above, could therefore be to allow another header line, namely "Content-type" as the *second* line in the template.
description: | updated |
root@nav: /usr/share/ pyshared/ nav/alertengine /dispatchers# diff -u email_dispatche r.py~ email_dispatcher.py r.py~ 2016-06-30 10:46:58.000000000 +0200 message. splitlines( )[1:])
--- email_dispatche
+++ email_dispatcher.py 2016-09-12 14:36:30.390898104 +0200
@@ -39,15 +39,24 @@
# Remove the subject line
message = '\n'.join(
+ content_ type='text/ plain' content_ type = message. splitlines( 1)[0].lstrip( 'Content- Type:') .strip( ) content_ type: content_ type message. splitlines( )[1:])
' X-NAV-alert- netbox' : alert.netbox,
' X-NAV-alert- device' : alert.device,
' X-NAV-alert- subsystem' : alert.source,
+ # Look for Content-type in next line
+ template_
+ if template_
+ content_type = template_
+ # Remove the Content-type line
+ message = '\n'.join(
+
headers = {
+ 'Content-type': content_type,
}
try: subject= subject, body=message, subject= subject, body=message, headers=headers,
to=[ address. address] )
email. send(fail_ silently= False)
if not address.DEBUG_MODE:
- email = EmailMessage(
+ email = EmailMessage(
else: