diff --git a/parameters.yaml b/parameters.yaml index 9917531..16831e0 100644 --- a/parameters.yaml +++ b/parameters.yaml @@ -137,9 +137,12 @@ html_logo: "logo.png" # E-mail notifications EMAIL: - mailserver: "localhost" + mailserver: "smtp.rub.de" # mail server + port: 465 # mail port + user: "seisox25" # mail user + password: "DOCKER" # mail password, read from environment variable if set to "ENV" or from docker secret if set to "DOCKER" addresses: ["marcel.paffrath@rub.de", "kasper.fischer@rub.de"] # list of mail addresses for info mails - sender: "webmaster@geophysik.ruhr-uni-bochum.de" # mail sender + sender: "RUB SeisObs " # mail sender stations_blacklist: [] # do not send emails for specific stations networks_blacklist: [] # do not send emails for specific network # specify recipients for single stations in a yaml: key = email-address, val = station list (e.g. [1Y.GR01, 1Y.GR02]) diff --git a/survBot.py b/survBot.py index 2117370..5d0f3eb 100755 --- a/survBot.py +++ b/survBot.py @@ -758,7 +758,28 @@ class StationQC(object): msg.add_alternative(html_str, subtype='html') # send message via SMTP server - s = smtplib.SMTP(server) + # set up starttls connection if server is not "localhost" + if server == 'localhost': + # create connection to localhost + s = smtplib.SMTP(server) + else: + password = mail_params.get('password') + # read password from docker secret if it is set to 'DOCKER' or + # read password from environment variable if it is set to 'ENV' + if password == 'DOCKER': + try: + with open('/run/secrets/mail_password', 'r') as f: + password = f.read().strip() + except FileNotFoundError as e: + logging.error('Could not read mail password from docker secret') + logging.error(e) + elif password == 'ENV': + password = os.environ.get(mail_params.get('password_env')) + # create SSL connection to server + s = smtplib.SMTP_SSL(server, mail_params.get('port')) + s.login(mail_params.get('user'), mail_params.get('password')) + + # send mail and close connection s.send_message(msg) s.quit()