Add custom subject field into email notification.

pull/149/head
Mark Jessop 2019-03-23 20:46:15 +10:30
rodzic 4a58de571b
commit 04b48db6a3
4 zmienionych plików z 24 dodań i 9 usunięć

Wyświetl plik

@ -486,7 +486,8 @@ def main():
_email_notification = EmailNotification(
smtp_server = config['email_smtp_server'],
mail_from = config['email_from'],
mail_to = config['email_to']
mail_to = config['email_to'],
mail_subject = config['email_subject']
)
exporter_objects.append(_email_notification)

Wyświetl plik

@ -40,11 +40,12 @@ def read_auto_rx_config(filename):
auto_rx_config = {
# Log Settings
'per_sonde_log' : True,
# Email Settings
'email_enabled': False,
'email_smtp_server': 'localhost',
'email_from': 'sonde@localhost',
'email_to': None,
# Email Settings
'email_enabled': False,
'email_smtp_server': 'localhost',
'email_from': 'sonde@localhost',
'email_to': None,
'email_subject': "<type> Sonde launch detected on <freq>: <id>",
# SDR Settings
'sdr_fm': 'rtl_fm',
'sdr_power': 'rtl_power',
@ -133,8 +134,9 @@ def read_auto_rx_config(filename):
auto_rx_config['email_smtp_server'] = config.get('email', 'smtp_server')
auto_rx_config['email_from'] = config.get('email', 'from')
auto_rx_config['email_to'] = config.get('email', 'to')
auto_rx_config['email_subject'] = config.get('email', 'subject')
except:
logging.error("Config - Invalid email settings. Disabling.")
logging.error("Config - Invalid or missing email settings. Disabling.")
auto_rx_config['email_enabled'] = False
# SDR Settings

Wyświetl plik

@ -32,11 +32,12 @@ class EmailNotification(object):
# We require the following fields to be present in the input telemetry dict.
REQUIRED_FIELDS = [ 'id', 'lat', 'lon', 'alt', 'type', 'freq']
def __init__(self, smtp_server = 'localhost', mail_from = None, mail_to = None):
def __init__(self, smtp_server = 'localhost', mail_from = None, mail_to = None, mail_subject = None):
""" Init a new E-Mail Notification Thread """
self.smtp_server = smtp_server
self.mail_from = mail_from
self.mail_to = mail_to
self.mail_subject = mail_subject
# Dictionary to track sonde IDs
self.sondes = {}
@ -103,7 +104,13 @@ class EmailNotification(object):
msg += 'https://sondehub.org/%s\n' % _id
msg = MIMEText(msg, 'plain', 'UTF-8')
msg['Subject'] = 'Sonde launch detected: ' + _id
# Construct subject
msg['Subject'] = self.mail_subject
msg['Subject'].replace('<id>', telemetry['id'])
msg['Subject'].replace('<type>', telemetry['type'])
msg['Subject'].replace('<freq>', telemetry['freq'])
msg['From'] = self.mail_from
msg['To'] = self.mail_to
msg["Date"] = formatdate()

Wyświetl plik

@ -219,6 +219,11 @@ email_enabled = False
smtp_server = localhost
from = sonde@localhost
to = someone@example.com
# Custom subject field. The following fields can be included:
# <freq> - Sonde Frequency, i.e. 401.520 MHz
# <type> - Sonde Type (RS94/RS41)
# <id> - Sonde Serial Number (i.e. M1234567)
subject = <type> Sonde launch detected on <freq>: <id>