0
0
Fork 0
mirror of https://github.com/alerta/alerta-contrib.git synced 2025-03-16 05:23:28 +00:00

Added smtp_username configuration variable to enable using mailer with email delivery service sendgrid.

This commit is contained in:
John Siegrist 2017-07-14 11:26:10 +10:00
parent c7ac9276f1
commit 0dc5ad6301
3 changed files with 17 additions and 2 deletions
integrations/mailer

View file

@ -46,6 +46,7 @@ mail_to = john.doe@gmail.com,jane.doe@gmail.com
mail_from = your.email@gmail.com
amqp_url = redis://localhost:6379/
dashboard_url = http://localhost:8000
smtp_username = alt.email@gmail.com
smtp_password = okvqhitqomebufyv
smtp_use_ssl = False
debug = True
@ -70,9 +71,14 @@ You can also use IP-authentication in your own SMTP server (by only
white-listing the alerta server IP), in such cases you should not
set the 'smtp_password' option to skip authentication altogether.
You can also set an alternate SMTP username for authenticating against
the email server if it differs from the 'mail_from' address. This is
required when using an email delivery service like sendgrid.
Application-specific passwords
https://support.google.com/accounts/answer/185833?hl=en
Rules File
----------
@ -113,6 +119,8 @@ replaced with only the contacts of the current matched rule.
Environment Variables
---------------------
``SMTP_USERNAME`` - can be used instead of smtp_username in the configuration file,
defaults to the value set for the mail_from field.
``SMTP_PASSWORD`` - can be used instead of smtp_password in the configuration file.
Email Format

View file

@ -50,6 +50,7 @@ DEFAULT_OPTIONS = {
'amqp_topic': 'notify',
'smtp_host': 'smtp.gmail.com',
'smtp_port': 587,
'smtp_username': '', # application-specific username if it differs from the specified 'mail_from' user
'smtp_password': '', # application-specific password if gmail used
'smtp_starttls': True, # use the STARTTLS SMTP extension
'smtp_use_ssl': False, # whether or not SSL is being used for the SMTP connection
@ -357,7 +358,7 @@ class MailSender(threading.Thread):
mx.starttls()
if OPTIONS['smtp_password']:
mx.login(OPTIONS['mail_from'], OPTIONS['smtp_password'])
mx.login(OPTIONS['smtp_username'], OPTIONS['smtp_password'])
mx.sendmail(OPTIONS['mail_from'],
contacts,
@ -468,6 +469,12 @@ def main():
OPTIONS['endpoint'] = os.environ.get('ALERTA_ENDPOINT') or OPTIONS['endpoint'] # nopep8
OPTIONS['key'] = os.environ.get('ALERTA_API_KEY') or OPTIONS['key']
OPTIONS['smtp_password'] = os.environ.get('SMTP_PASSWORD') or OPTIONS['smtp_password'] # nopep8
if os.environ.get('SMTP_USERNAME'):
OPTIONS['smtp_username'] = os.environ.get('SMTP_USERNAME')
elif not OPTIONS['smtp_username']:
OPTIONS['smtp_username'] = OPTIONS['mail_from']
if os.environ.get('DEBUG'):
OPTIONS['debug'] = True

View file

@ -2,7 +2,7 @@
import setuptools
version = '3.4.0'
version = '3.5.0'
setuptools.setup(
name="alerta-mailer",