Skip to content
Permalink
Browse files

Don't show email based elements if email doesn't work

  • Loading branch information...
overshard committed Jul 4, 2018
1 parent e71f849 commit 268df044fbe62fabfacd1a5b4d01485cc4b57b42
@@ -203,8 +203,23 @@ per-site basis. These settings must be supplied to support features such as
password reset. To access the settings, navigate to `/admin/sites/site/` and
select the site to modify.

If you are using Heroku you can add `sendgrid` to your apps addons on the
Heroku admin panel or by running:
#### Email Docker

You can configure email by setting environmental variables in the
`docker-compose` config for `web`. These would be:

- **EMAIL_HOST**
- **EMAIL_HOST_USER**
- **EMAIL_HOST_PASSWORD**
- **EMAIL_PORT** defaults to port `25`
- **EMAIL_USE_TLS** defaults to `False`, you can set this to `True`

These would go where the `SECRET_KEY` environmental variable is set

#### Email Heroku

You can add `sendgrid` to your apps addons on the Heroku admin panel or by
running:

heroku addons:create sendgrid

@@ -66,9 +66,14 @@
</div>

<div class="bg-light text-center px-4 py-3 rounded-bottom">
{% if EMAIL_ENABLED %}
<a
href="{% url 'password_reset' %}">
Forgot your password?
</a>
{% else %}
<div class="text-muted">Forgot your password?<br>
Please contact your Timestrap administrator.</div>
{% endif %}
</div>
{% endblock %}
@@ -0,0 +1,7 @@
from django.conf import settings


def template_settings(request):
return {
'EMAIL_ENABLED': settings.EMAIL_ENABLED,
}
@@ -67,6 +67,8 @@
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',

'timestrap.context_processors.template_settings',
],
},
},
@@ -110,6 +112,8 @@

EMAIL_BACKEND = 'conf.backends.mail.EmailBackend'

EMAIL_ENABLED = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/
@@ -29,6 +29,13 @@


# Email
# TODO: Need to set this up to not just output to console...

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
if os.environ.get('EMAIL_HOST'): # noqa: E501,F405
EMAIL_HOST = os.environ.get('EMAIL_HOST') # noqa: F405
EMAIL_HOST_USER = os.environ.get('EMAIL_HOST_USER') # noqa: F405
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD') # noqa: F405
EMAIL_PORT = int(os.environ.get('EMAIL_PORT', 25)) # noqa: F405
EMAIL_USE_TLS = bool(os.environ.get('EMAIL_USE_TLS', False)) # noqa: F405
else:
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
EMAIL_ENABLED = False
@@ -29,14 +29,13 @@
SENDGRID_USERNAME = os.environ.get('SENDGRID_USERNAME', None) # noqa: F405
SENDGRID_PASSWORD = os.environ.get('SENDGRID_PASSWORD', None) # noqa: F405

# Use SendGrid if we have the addon installed, else just print to console which
# is accessible via Heroku logs
# Use SendGrid if we have the addon installed
if SENDGRID_USERNAME and SENDGRID_PASSWORD:
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_HOST_USER = SENDGRID_USERNAME
EMAIL_HOST_PASSWORD = SENDGRID_PASSWORD
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_TIMEOUT = 60
else:
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
EMAIL_ENABLED = False

0 comments on commit 268df04

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.