Update email parameters in parameters.yaml and modify SMTP connection in survBot.py
- Update mailserver, port, user, password, and sender in parameters.yaml - Modify SMTP connection in survBot.py to support starttls connection if server is not "localhost" - Read password from docker secret or environment variable if set to 'DOCKER' or 'ENV' respectively
This commit is contained in:
parent
3e47f4275b
commit
db27220505
@ -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 <seisobs@ruhr-uni-bochum.de>" # 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])
|
||||
|
23
survBot.py
23
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()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user