diff --git a/seahub/auth/forms.py b/seahub/auth/forms.py index 46191fd7f7..bb4d991596 100644 --- a/seahub/auth/forms.py +++ b/seahub/auth/forms.py @@ -1,5 +1,4 @@ from django.contrib.sites.models import Site -from django.template import Context, loader from django import forms from django.utils.translation import ugettext_lazy as _ from django.utils.http import int_to_base36 @@ -7,7 +6,7 @@ from django.utils.http import int_to_base36 from seahub.base.accounts import User from seahub.auth import authenticate from seahub.auth.tokens import default_token_generator -from seahub.utils import IS_EMAIL_CONFIGURED, get_service_url +from seahub.utils import IS_EMAIL_CONFIGURED, send_html_email from captcha.fields import CaptchaField @@ -86,7 +85,6 @@ class PasswordResetForm(forms.Form): """ Generates a one-use only link for resetting password and sends to the user """ - from django.core.mail import EmailMessage user = self.users_cache if not domain_override: @@ -95,24 +93,15 @@ class PasswordResetForm(forms.Form): else: site_name = domain_override - service_url = get_service_url() - t = loader.get_template(email_template_name) - c = { 'email': user.username, - 'site_name': site_name, 'uid': int_to_base36(user.id), 'user': user, 'token': token_generator.make_token(user), - 'service_url': service_url, - 'media_url': settings.MEDIA_URL, - 'logo_path': settings.LOGO_PATH, } - msg = EmailMessage(_("Reset Password on %s") % site_name, - t.render(Context(c)), None, [user.username]) - msg.content_subtype = "html" # Main content is now text/html - msg.send() + send_html_email(_("Reset Password on %s") % site_name, + email_template_name, c, None, [user.username]) class SetPasswordForm(forms.Form): """ diff --git a/seahub/group/views.py b/seahub/group/views.py index 12d0401635..4595214b2e 100644 --- a/seahub/group/views.py +++ b/seahub/group/views.py @@ -6,7 +6,6 @@ import simplejson as json import urllib2 from django.conf import settings -from django.core.mail import EmailMessage from django.core.paginator import EmptyPage, InvalidPage from django.core.urlresolvers import reverse from django.contrib import messages @@ -50,11 +49,11 @@ from seahub.wiki import get_group_wiki_repo, get_group_wiki_page, convert_wiki_l get_wiki_pages from seahub.wiki.models import WikiDoesNotExist, WikiPageMissing, GroupWiki from seahub.wiki.utils import clean_page_name, get_wiki_dirent -from seahub.settings import SITE_ROOT, SITE_NAME, MEDIA_URL, LOGO_PATH +from seahub.settings import SITE_ROOT, SITE_NAME from seahub.shortcuts import get_first_object_or_none from seahub.utils import render_error, render_permission_error, string2list, \ check_and_get_org_by_group, gen_file_get_url, get_file_type_and_ext, \ - calc_file_path_hash, is_valid_username, get_service_url, send_html_email + calc_file_path_hash, is_valid_username, send_html_email from seahub.utils.file_types import IMAGE from seahub.utils.paginator import Paginator from seahub.views import is_registered_user diff --git a/seahub/notifications/management/commands/send_notices.py b/seahub/notifications/management/commands/send_notices.py index f98bda3f60..ff50e399df 100644 --- a/seahub/notifications/management/commands/send_notices.py +++ b/seahub/notifications/management/commands/send_notices.py @@ -3,13 +3,12 @@ import datetime import logging import string -from django.core.mail import EmailMessage from django.core.management.base import BaseCommand, CommandError from django.core.urlresolvers import reverse from seahub.base.models import CommandsLastCheck from seahub.notifications.models import UserNotification -from seahub.utils import get_service_url +from seahub.utils import send_html_email import seahub.settings as settings from django.template import Context, loader @@ -19,9 +18,6 @@ logger = logging.getLogger(__name__) site_name = settings.SITE_NAME subjects = (u'New notice on %s' % site_name, u'New notices on %s' % site_name) -service_url = get_service_url() -media_url = settings.MEDIA_URL -logo_path = settings.LOGO_PATH class Command(BaseCommand): help = 'Send Email notifications to user if he/she has an unread notices every period of seconds .' @@ -63,21 +59,15 @@ class Command(BaseCommand): for to_user, count in email_ctx.items(): subject = subjects[1] if count > 1 else subjects[0] - t = loader.get_template('notifications/notice_email.html') c = { - 'site_name': site_name, - 'media_url': media_url, - 'logo_path': logo_path, - 'service_url': service_url, 'to_user': to_user, 'notice_count': count, } try: - msg = EmailMessage(subject, t.render(Context(c)), settings.DEFAULT_FROM_EMAIL, - [to_user]) - msg.content_subtype = "html" - msg.send() + send_html_email(subject, 'notifications/notice_email.html', c, + settings.DEFAULT_FROM_EMAIL, [to_user]) + logger.info('Successfully sent email to %s' % to_user) except Exception, e: diff --git a/seahub/notifications/templates/notifications/notice_email.html b/seahub/notifications/templates/notifications/notice_email.html index dd2af967a2..eae086e5e8 100644 --- a/seahub/notifications/templates/notifications/notice_email.html +++ b/seahub/notifications/templates/notifications/notice_email.html @@ -17,7 +17,7 @@ You've got {{num}} new notices on {{ site_name }}.
{% trans "Go check out at the following page:" %}
-{{ service_url }}{% url 'user_notification_list' %}
+{{ url_base }}{% url 'user_notification_list' %}