From 647e16405455dcb584211d09aaa97d5c1f819877 Mon Sep 17 00:00:00 2001 From: Joshua Tauberer Date: Mon, 31 Jul 2017 17:54:17 -0400 Subject: [PATCH] use the console email backend by default, which is good for local testing, or sparkpost if a setting is set fixes #144 --- settings.env.template | 1 + settings.py | 9 ++------- settings_env.py | 9 +++++++++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/settings.env.template b/settings.env.template index 8a16b26a..3d659546 100644 --- a/settings.env.template +++ b/settings.env.template @@ -74,3 +74,4 @@ FACEBOOK_AUTH_SCOPE=email GOOGLE_APP_ID=fill this in GOOGLE_APP_SECRET=fill this in GOOGLE_AUTH_SCOPE="openid email" +SPARKPOST_API_KEY=fill this in diff --git a/settings.py b/settings.py index 073a1a0f..60a99f83 100644 --- a/settings.py +++ b/settings.py @@ -63,10 +63,8 @@ CSRF_COOKIE_SECURE = not DEBUG # similarly SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer' # needed by openid login -EMAIL_HOST = 'localhost' -EMAIL_PORT = 587 -#EMAIL_HOST_USER = '' -#EMAIL_HOST_PASSWORD = '' +EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' +EMAIL_SUBJECT_PREFIX = '[GovTrack] ' # List of callables that know how to import templates from various sources. TEMPLATE_LOADERS = ( @@ -170,9 +168,6 @@ EMAIL_UPDATES_RETURN_PATH = "GovTrack.us Email Updates " BOUNCES_UID_REGEX = re.compile(r"?", re.I) -#if DEBUG: # sometimes we debug in a live environment -# EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' - # Load settings from the environment from settings_env import * diff --git a/settings_env.py b/settings_env.py index f2a4f08a..30df52ef 100644 --- a/settings_env.py +++ b/settings_env.py @@ -80,10 +80,19 @@ def get_env_boolvar(var_name, default=NOT_SET): "GOOGLE_ANALYTICS_KEY", "TWITTER_ACCESS_TOKEN", # for automated tweets and to update @GovTrack/Members-of-Congress twitter list "TWITTER_ACCESS_TOKEN_SECRET", + "SPARKPOST_API_KEY", ] for var in copy_env_vars: locals()[var] = get_env_variable(var, default='') +if SPARKPOST_API_KEY: + EMAIL_BACKEND = 'sparkpost.django.email_backend.SparkPostEmailBackend' + SPARKPOST_OPTIONS = { + 'track_opens': False, + 'track_clicks': False, + 'transactional': True, + } + # TODO. The ad-free payment requires something like this: #import paypalrestsdk #paypalrestsdk.configure(mode="sandbox", client_id="...", client_secret="...")