mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-10 15:32:38 -07:00
Allow HTML emails
This commit is contained in:
parent
972412e712
commit
c5dff312e1
2 changed files with 53 additions and 24 deletions
|
@ -1122,6 +1122,11 @@ def strip_tag(data, agent_id=None):
|
||||||
'a': ['href'],
|
'a': ['href'],
|
||||||
'font': ['color']}
|
'font': ['color']}
|
||||||
return bleach.clean(data, tags=whitelist.keys(), attributes=whitelist, strip=True)
|
return bleach.clean(data, tags=whitelist.keys(), attributes=whitelist, strip=True)
|
||||||
|
|
||||||
|
elif agent_id == 10:
|
||||||
|
# Don't remove tags for email
|
||||||
|
return data
|
||||||
|
|
||||||
elif agent_id == 13:
|
elif agent_id == 13:
|
||||||
# Allow tags b, i, code, pre, a[href] for Telegram
|
# Allow tags b, i, code, pre, a[href] for Telegram
|
||||||
whitelist = {'b': [],
|
whitelist = {'b': [],
|
||||||
|
|
|
@ -17,10 +17,12 @@ from urlparse import urlparse
|
||||||
import base64
|
import base64
|
||||||
import json
|
import json
|
||||||
import cherrypy
|
import cherrypy
|
||||||
|
from email.mime.multipart import MIMEMultipart
|
||||||
from email.mime.text import MIMEText
|
from email.mime.text import MIMEText
|
||||||
import email.utils
|
import email.utils
|
||||||
from httplib import HTTPSConnection
|
from httplib import HTTPSConnection
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import requests
|
import requests
|
||||||
import shlex
|
import shlex
|
||||||
import smtplib
|
import smtplib
|
||||||
|
@ -1496,35 +1498,51 @@ class BOXCAR(object):
|
||||||
class Email(object):
|
class Email(object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
self.from_name = plexpy.CONFIG.EMAIL_FROM_NAME
|
||||||
|
self.email_from = plexpy.CONFIG.EMAIL_FROM
|
||||||
|
self.email_to = plexpy.CONFIG.EMAIL_TO
|
||||||
|
self.email_cc = plexpy.CONFIG.EMAIL_CC
|
||||||
|
self.email_bcc = plexpy.CONFIG.EMAIL_BCC
|
||||||
|
self.smtp_server = plexpy.CONFIG.EMAIL_SMTP_SERVER
|
||||||
|
self.smtp_port = plexpy.CONFIG.EMAIL_SMTP_PORT
|
||||||
|
self.smtp_user = plexpy.CONFIG.EMAIL_SMTP_USER
|
||||||
|
self.smtp_password = plexpy.CONFIG.EMAIL_SMTP_PASSWORD
|
||||||
|
self.tls = plexpy.CONFIG.EMAIL_TLS
|
||||||
|
self.html_support = plexpy.CONFIG.TELEGRAM_HTML_SUPPORT
|
||||||
|
|
||||||
def notify(self, subject, message):
|
def notify(self, subject, message):
|
||||||
if not subject or not message:
|
if not subject or not message:
|
||||||
return
|
return
|
||||||
|
|
||||||
message = MIMEText(message, 'plain', "utf-8")
|
msg = MIMEMultipart('alternative')
|
||||||
message['Subject'] = subject
|
msg['Subject'] = subject
|
||||||
message['From'] = email.utils.formataddr((plexpy.CONFIG.EMAIL_FROM_NAME, plexpy.CONFIG.EMAIL_FROM))
|
msg['From'] = email.utils.formataddr((self.from_name, self.email_from))
|
||||||
message['To'] = plexpy.CONFIG.EMAIL_TO
|
msg['To'] = self.email_to
|
||||||
message['CC'] = plexpy.CONFIG.EMAIL_CC
|
msg['CC'] = self.email_cc
|
||||||
|
|
||||||
recipients = [x.strip() for x in plexpy.CONFIG.EMAIL_TO.split(';')] \
|
p = re.compile(r'<.*?>')
|
||||||
+ [x.strip() for x in plexpy.CONFIG.EMAIL_CC.split(';')] \
|
plain_message = p.sub('', message)
|
||||||
+ [x.strip() for x in plexpy.CONFIG.EMAIL_BCC.split(';')]
|
|
||||||
|
msg.attach(MIMEText(plain_message, 'plain'))
|
||||||
|
msg.attach(MIMEText(message, 'html'))
|
||||||
|
|
||||||
|
recipients = [x.strip() for x in self.email_to.split(';')] \
|
||||||
|
+ [x.strip() for x in self.email_cc.split(';')] \
|
||||||
|
+ [x.strip() for x in self.email_bcc.split(';')]
|
||||||
recipients = filter(None, recipients)
|
recipients = filter(None, recipients)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
mailserver = smtplib.SMTP(plexpy.CONFIG.EMAIL_SMTP_SERVER, plexpy.CONFIG.EMAIL_SMTP_PORT)
|
mailserver = smtplib.SMTP(self.smtp_server, self.smtp_port)
|
||||||
|
|
||||||
if (plexpy.CONFIG.EMAIL_TLS):
|
if self.tls:
|
||||||
mailserver.starttls()
|
mailserver.starttls()
|
||||||
|
|
||||||
mailserver.ehlo()
|
mailserver.ehlo()
|
||||||
|
|
||||||
if plexpy.CONFIG.EMAIL_SMTP_USER:
|
if self.smtp_user:
|
||||||
mailserver.login(plexpy.CONFIG.EMAIL_SMTP_USER, plexpy.CONFIG.EMAIL_SMTP_PASSWORD)
|
mailserver.login(self.smtp_user, self.smtp_password)
|
||||||
|
|
||||||
mailserver.sendmail(plexpy.CONFIG.EMAIL_FROM, recipients, message.as_string())
|
mailserver.sendmail(self.email_from, recipients, msg.as_string())
|
||||||
mailserver.quit()
|
mailserver.quit()
|
||||||
|
|
||||||
logger.info(u"PlexPy Notifiers :: Email notification sent.")
|
logger.info(u"PlexPy Notifiers :: Email notification sent.")
|
||||||
|
@ -1536,64 +1554,70 @@ class Email(object):
|
||||||
|
|
||||||
def return_config_options(self):
|
def return_config_options(self):
|
||||||
config_option = [{'label': 'From Name',
|
config_option = [{'label': 'From Name',
|
||||||
'value': plexpy.CONFIG.EMAIL_FROM_NAME,
|
'value': self.from_name,
|
||||||
'name': 'email_from_name',
|
'name': 'email_from_name',
|
||||||
'description': 'The name of the sender.',
|
'description': 'The name of the sender.',
|
||||||
'input_type': 'text'
|
'input_type': 'text'
|
||||||
},
|
},
|
||||||
{'label': 'From',
|
{'label': 'From',
|
||||||
'value': plexpy.CONFIG.EMAIL_FROM,
|
'value': self.email_from,
|
||||||
'name': 'email_from',
|
'name': 'email_from',
|
||||||
'description': 'The email address of the sender.',
|
'description': 'The email address of the sender.',
|
||||||
'input_type': 'text'
|
'input_type': 'text'
|
||||||
},
|
},
|
||||||
{'label': 'To',
|
{'label': 'To',
|
||||||
'value': plexpy.CONFIG.EMAIL_TO,
|
'value': self.email_to,
|
||||||
'name': 'email_to',
|
'name': 'email_to',
|
||||||
'description': 'The email address(es) of the recipients, separated by semicolons (;).',
|
'description': 'The email address(es) of the recipients, separated by semicolons (;).',
|
||||||
'input_type': 'text'
|
'input_type': 'text'
|
||||||
},
|
},
|
||||||
{'label': 'CC',
|
{'label': 'CC',
|
||||||
'value': plexpy.CONFIG.EMAIL_CC,
|
'value': self.email_cc,
|
||||||
'name': 'email_cc',
|
'name': 'email_cc',
|
||||||
'description': 'The email address(es) to CC, separated by semicolons (;).',
|
'description': 'The email address(es) to CC, separated by semicolons (;).',
|
||||||
'input_type': 'text'
|
'input_type': 'text'
|
||||||
},
|
},
|
||||||
{'label': 'BCC',
|
{'label': 'BCC',
|
||||||
'value': plexpy.CONFIG.EMAIL_BCC,
|
'value': self.email_bcc,
|
||||||
'name': 'email_bcc',
|
'name': 'email_bcc',
|
||||||
'description': 'The email address(es) to BCC, separated by semicolons (;).',
|
'description': 'The email address(es) to BCC, separated by semicolons (;).',
|
||||||
'input_type': 'text'
|
'input_type': 'text'
|
||||||
},
|
},
|
||||||
{'label': 'SMTP Server',
|
{'label': 'SMTP Server',
|
||||||
'value': plexpy.CONFIG.EMAIL_SMTP_SERVER,
|
'value': self.smtp_server,
|
||||||
'name': 'email_smtp_server',
|
'name': 'email_smtp_server',
|
||||||
'description': 'Host for the SMTP server.',
|
'description': 'Host for the SMTP server.',
|
||||||
'input_type': 'text'
|
'input_type': 'text'
|
||||||
},
|
},
|
||||||
{'label': 'SMTP Port',
|
{'label': 'SMTP Port',
|
||||||
'value': plexpy.CONFIG.EMAIL_SMTP_PORT,
|
'value': self.smtp_port,
|
||||||
'name': 'email_smtp_port',
|
'name': 'email_smtp_port',
|
||||||
'description': 'Port for the SMTP server.',
|
'description': 'Port for the SMTP server.',
|
||||||
'input_type': 'number'
|
'input_type': 'number'
|
||||||
},
|
},
|
||||||
{'label': 'SMTP User',
|
{'label': 'SMTP User',
|
||||||
'value': plexpy.CONFIG.EMAIL_SMTP_USER,
|
'value': self.smtp_user,
|
||||||
'name': 'email_smtp_user',
|
'name': 'email_smtp_user',
|
||||||
'description': 'User for the SMTP server.',
|
'description': 'User for the SMTP server.',
|
||||||
'input_type': 'text'
|
'input_type': 'text'
|
||||||
},
|
},
|
||||||
{'label': 'SMTP Password',
|
{'label': 'SMTP Password',
|
||||||
'value': plexpy.CONFIG.EMAIL_SMTP_PASSWORD,
|
'value': self.smtp_password,
|
||||||
'name': 'email_smtp_password',
|
'name': 'email_smtp_password',
|
||||||
'description': 'Password for the SMTP server.',
|
'description': 'Password for the SMTP server.',
|
||||||
'input_type': 'password'
|
'input_type': 'password'
|
||||||
},
|
},
|
||||||
{'label': 'TLS',
|
{'label': 'TLS',
|
||||||
'value': plexpy.CONFIG.EMAIL_TLS,
|
'value': self.tls,
|
||||||
'name': 'email_tls',
|
'name': 'email_tls',
|
||||||
'description': 'Does the server use encryption.',
|
'description': 'Does the server use encryption.',
|
||||||
'input_type': 'checkbox'
|
'input_type': 'checkbox'
|
||||||
|
},
|
||||||
|
{'label': 'Enable HTML Support',
|
||||||
|
'value': self.html_support,
|
||||||
|
'name': 'email_html_support',
|
||||||
|
'description': 'Style your messages using HTML tags.',
|
||||||
|
'input_type': 'checkbox'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue