diff --git a/src/postorius/models.py b/src/postorius/models.py index baf1cef..295cd24 100644 --- a/src/postorius/models.py +++ b/src/postorius/models.py @@ -26,6 +26,7 @@ from datetime import datetime, timedelta from django.conf import settings from django.contrib.auth.models import User +from django.core.exceptions import ImproperlyConfigured from django.core.urlresolvers import reverse from django.core.mail import send_mail from django.db import models @@ -227,7 +228,7 @@ def __unicode__(self): return u'Address Confirmation Profile for {0}'.format(self.email) - + @property def is_expired(self): """ @@ -265,9 +266,9 @@ >>> EMAIL_CONFIRMATION_SUBJECT = 'Confirmation needed' :param request: The HTTP request object. - :type request: HTTPRequest + :type request: HTTPRequest :param template_context: The context used when rendering the template. - Falls back to host url and activation link. + Falls back to host url and activation link. :type template_context: django.template.Context """ # create the host url and the activation link need for the template @@ -276,7 +277,7 @@ url = reverse('address_activation_link', kwargs={'activation_key': self.activation_key}) activation_link = '{0}{1}'.format(host_url, url) - # Detect the right template path, either from the param, + # Detect the right template path, either from the param, # the setting or the default if not template_path: template_path = getattr(settings, @@ -289,7 +290,18 @@ {'activation_link': activation_link, 'host_url': host_url}) email_subject = getattr( settings, 'EMAIL_CONFIRMATION_SUBJECT', u'Confirmation needed') + try: + sender_address = getattr(settings, 'EMAIL_CONFIRMATION_FROM') + except AttributeError: + # settings.EMAIL_CONFIRMATION_FROM is not defined, fallback + # settings.DEFAULT_EMAIL_FROM as mentioned in the django + # docs. If that also fails, raise a `ImproperlyConfigured` Error. + try: + sender_address = getattr(settings, 'DEFAULT_FROM_EMAIL') + except AttributeError: + raise ImproperlyConfigured + send_mail(email_subject, get_template(template_path).render(template_context), - getattr(settings, 'EMAIL_CONFIRMATION_FROM'), + sender_address, [self.email]) diff --git a/src/postorius/templates/postorius/base.html b/src/postorius/templates/postorius/base.html index 308231b..063e08b 100644 --- a/src/postorius/templates/postorius/base.html +++ b/src/postorius/templates/postorius/base.html @@ -3,7 +3,7 @@ -
{% trans "A confirmation link has been sent to the email address you submitted. Please check your email account and click on the confirmation link to add this address for your account." %}
{% endblock main %} - diff --git a/src/postorius/urls.py b/src/postorius/urls.py index c4da4ac..68341b2 100644 --- a/src/postorius/urls.py +++ b/src/postorius/urls.py @@ -42,7 +42,7 @@ ListSummaryView.as_view( ), name='list_summary'), url(r'^subscribe$', - ListSubsribeView.as_view( + ListSubscribeView.as_view( ), name='list_subscribe'), url(r'^unsubscribe/(?P