diff --git a/seahub/auth/forms.py b/seahub/auth/forms.py index 05f4ed5b22..46191fd7f7 100644 --- a/seahub/auth/forms.py +++ b/seahub/auth/forms.py @@ -7,7 +7,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 +from seahub.utils import IS_EMAIL_CONFIGURED, get_service_url from captcha.fields import CaptchaField @@ -92,24 +92,24 @@ class PasswordResetForm(forms.Form): if not domain_override: current_site = Site.objects.get_current() site_name = current_site.name - domain = current_site.domain else: - site_name = domain = domain_override + site_name = domain_override + + service_url = get_service_url() t = loader.get_template(email_template_name) c = { 'email': user.username, - 'domain': domain, 'site_name': site_name, 'uid': int_to_base36(user.id), 'user': user, 'token': token_generator.make_token(user), - 'protocol': use_https and 'https' or 'http', + 'service_url': service_url, 'media_url': settings.MEDIA_URL, 'logo_path': settings.LOGO_PATH, } - msg = EmailMessage(_("Password reset on %s") % site_name, + 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() diff --git a/seahub/group/templates/group/add_member_email.html b/seahub/group/templates/group/add_member_email.html index 211e966036..db82b6f3f3 100644 --- a/seahub/group/templates/group/add_member_email.html +++ b/seahub/group/templates/group/add_member_email.html @@ -1,9 +1,18 @@ -{% load url from future %}{% load i18n %}{% autoescape off %} -{% blocktrans %}{{ email }} invite you to join group {{ group.group_name }}. Please go to the following page and sign up:{% endblocktrans %} -{{ protocol }}://{{ domain }}{% url 'registration_register' %}?src={{ to_email }} +{% extends 'email_base.html' %} -{% trans "Thanks for using our site!" %} +{% load i18n seahub_tags %} -{% blocktrans %}The {{ site_name }} team{% endblocktrans %} +{% block email_con %} +{% autoescape off %} + +

{% trans "Hi, " %}

+ +

+{% blocktrans with grp_name=group.group_name %}{{ email }} invited you to join group {{ grp_name }} on {{ site_name }}: {% endblocktrans %}
+{{ service_url }}{% url 'registration_register' %}?src={{ to_email }} +

{% endautoescape %} +{% endblock %} + + diff --git a/seahub/group/views.py b/seahub/group/views.py index 291041ba36..9c46a1942a 100644 --- a/seahub/group/views.py +++ b/seahub/group/views.py @@ -6,7 +6,7 @@ import simplejson as json import urllib2 from django.conf import settings -from django.core.mail import send_mail +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 +50,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 +from seahub.settings import SITE_ROOT, SITE_NAME, MEDIA_URL, LOGO_PATH 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 + calc_file_path_hash, is_valid_username, get_service_url from seahub.utils.file_types import IMAGE from seahub.utils.paginator import Paginator from seahub.views import is_registered_user @@ -640,21 +640,23 @@ def group_manage(request, group_id): continue if not is_registered_user(email): - use_https = request.is_secure() - domain = RequestSite(request).domain + service_url = get_service_url() t = loader.get_template('group/add_member_email.html') c = { 'email': username, 'to_email': email, 'group': group, - 'domain': domain, - 'protocol': use_https and 'https' or 'http', + 'service_url': service_url, 'site_name': SITE_NAME, + 'media_url': MEDIA_URL, + 'logo_path': LOGO_PATH, } try: - send_mail(_(u'Your friend added you to a group at Seafile.'), - t.render(Context(c)), None, [email], - fail_silently=False) + msg = EmailMessage(_(u'You are invited to join a group on %s.') % SITE_NAME, + t.render(Context(c)), None, [email]) + msg.content_subtype = "html" + msg.send() + mail_sended_list.append(email) except Exception, e: logger.warn(e) diff --git a/seahub/notifications/management/commands/send_notices.py b/seahub/notifications/management/commands/send_notices.py index b285910faf..f98bda3f60 100644 --- a/seahub/notifications/management/commands/send_notices.py +++ b/seahub/notifications/management/commands/send_notices.py @@ -3,44 +3,28 @@ import datetime import logging import string -from django.core.mail import send_mail +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 import seahub.settings as settings +from django.template import Context, loader + # Get an instance of a logger logger = logging.getLogger(__name__) -email_templates = (u'''Hi, ${to_user} -You've got ${count} new notice on ${site_name}. - -Go check out at ${url} - -Thanks for using our site! - -${site_name} team -''', -u'''Hi, ${to_user} -You've got ${count} new notices on ${site_name}. - -Go check out at ${url} - -Thanks for using our site! - -${site_name} team -''') - - - site_name = settings.SITE_NAME subjects = (u'New notice on %s' % site_name, u'New notices on %s' % site_name) -url = settings.SITE_BASE.rstrip('/') + reverse('user_notification_list') +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 a unread notices every period of seconds .' + help = 'Send Email notifications to user if he/she has an unread notices every period of seconds .' label = "notifications_send_notices" def handle(self, *args, **options): @@ -79,14 +63,22 @@ class Command(BaseCommand): for to_user, count in email_ctx.items(): subject = subjects[1] if count > 1 else subjects[0] - template = string.Template(email_templates[1]) if count > 1 else \ - string.Template(email_templates[0]) - content = template.substitute(to_user=to_user, count=count, - site_name=site_name, url=url) + 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: - send_mail(subject, content, settings.DEFAULT_FROM_EMAIL, - [to_user], fail_silently=False) + msg = EmailMessage(subject, t.render(Context(c)), settings.DEFAULT_FROM_EMAIL, + [to_user]) + msg.content_subtype = "html" + msg.send() logger.info('Successfully sent email to %s' % to_user) + except Exception, e: logger.error('Failed to send email to %s, error detail: %s' % (to_user, e)) diff --git a/seahub/notifications/templates/notifications/notice_email.html b/seahub/notifications/templates/notifications/notice_email.html new file mode 100644 index 0000000000..dd2af967a2 --- /dev/null +++ b/seahub/notifications/templates/notifications/notice_email.html @@ -0,0 +1,24 @@ +{% extends 'email_base.html' %} + +{% load i18n seahub_tags %} + +{% block email_con %} +{% autoescape off %} + +

{% blocktrans with name=to_user|email2nickname %}Hi {{ name }},{% endblocktrans %}

+ +

+{% blocktrans count num=notice_count %} +You've got 1 new notice on {{ site_name }}. +{% plural %} +You've got {{num}} new notices on {{ site_name }}. +{% endblocktrans %} +

+ +

+{% trans "Go check out at the following page:" %}
+{{ service_url }}{% url 'user_notification_list' %} +

+ +{% endautoescape %} +{% endblock %} diff --git a/seahub/share/views.py b/seahub/share/views.py index 51f9330d40..92a20e2def 100644 --- a/seahub/share/views.py +++ b/seahub/share/views.py @@ -37,7 +37,7 @@ from seahub.views import validate_owner, is_registered_user from seahub.utils import render_permission_error, string2list, render_error, \ gen_token, gen_shared_link, gen_shared_upload_link, gen_dir_share_link, \ gen_file_share_link, IS_EMAIL_CONFIGURED, check_filename_with_rename, \ - get_repo_last_modify, is_valid_username + get_repo_last_modify, is_valid_username, get_service_url import seahub.settings as settings try: @@ -800,21 +800,19 @@ def send_shared_link(request): mail_sended.send(sender=None, user=request.user.username, email=to_email) - use_https = request.is_secure() - domain = RequestSite(request).domain + service_url = get_service_url() c = { 'email': request.user.username, 'to_email': to_email, 'file_shared_link': file_shared_link, 'site_name': SITE_NAME, - 'domain': domain, - 'protocol': use_https and 'https' or 'http', + 'service_url': service_url, 'media_url': settings.MEDIA_URL, 'logo_path': settings.LOGO_PATH, - } + } try: - msg = EmailMessage(_(u'Your friend shared a file to you on Seafile'), + msg = EmailMessage(_(u'A file is shared to you on s%') % SITE_NAME, t.render(Context(c)), None, [to_email]) msg.content_subtype = "html" msg.send() @@ -1081,22 +1079,19 @@ def send_shared_upload_link(request): mail_sended.send(sender=None, user=request.user.username, email=to_email) - - use_https = request.is_secure() - domain = RequestSite(request).domain + service_url = get_service_url() c = { 'email': request.user.username, 'to_email': to_email, 'shared_upload_link': shared_upload_link, 'site_name': SITE_NAME, - 'domain': domain, - 'protocol': use_https and 'https' or 'http', + 'service_url': service_url, 'media_url': settings.MEDIA_URL, 'logo_path': settings.LOGO_PATH, } try: - msg = EmailMessage(_(u'Your friend shared a upload link to you on Seafile'), + msg = EmailMessage(_(u'An upload link is shared to you on s%') % SITE_NAME, t.render(Context(c)), None, [to_email]) msg.content_subtype = "html" msg.send() diff --git a/seahub/templates/email_base.html b/seahub/templates/email_base.html index 64783187f5..414f300963 100644 --- a/seahub/templates/email_base.html +++ b/seahub/templates/email_base.html @@ -1,7 +1,7 @@ {% load i18n %}
- +
{% block email_con %}{% endblock %} diff --git a/seahub/templates/registration/password_reset_email.html b/seahub/templates/registration/password_reset_email.html index 6a975cc618..4663eeacef 100644 --- a/seahub/templates/registration/password_reset_email.html +++ b/seahub/templates/registration/password_reset_email.html @@ -8,17 +8,13 @@

{% trans "Hi," %}

-

{% blocktrans %}You're receiving this e-mail because you requested a password reset for your user account at {{ site_name }}. {% endblocktrans %}

-

-{% trans "Please go to the following page and choose a new password:" %}
-{% block reset_link %} -{{ protocol }}://{{ domain }}{% url 'auth_password_reset_confirm' uidb36=uid token=token %} -{% endblock %} +{% blocktrans with account=user.username %}To reset the password of your account {{ account }} on {{ site_name }}, please click the following link: {% endblocktrans %}
+{{ service_url }}{% url 'auth_password_reset_confirm' uidb36=uid token=token %}

-{% trans "Your username, in case you've forgotten:" %} {{ user.username }} +{% trans "If you did not request it, just skip it." %}

{% endautoescape %} diff --git a/seahub/templates/shared_link_email.html b/seahub/templates/shared_link_email.html index c1b4f4b808..81cda4b17a 100644 --- a/seahub/templates/shared_link_email.html +++ b/seahub/templates/shared_link_email.html @@ -9,11 +9,7 @@

{% trans "Hi," %}

-{% blocktrans %}You're receiving this e-mail because {{ email }} is sharing a file to you on {{ site_name }}.{% endblocktrans%} -

- -

-{% trans "Please go to the following page and view the file:" %}
+{% blocktrans %}{{ email }} shared a file to you on {{ site_name }}:{% endblocktrans%}
{{ file_shared_link }}

diff --git a/seahub/templates/shared_upload_link_email.html b/seahub/templates/shared_upload_link_email.html index d99a660396..09c0558e31 100644 --- a/seahub/templates/shared_upload_link_email.html +++ b/seahub/templates/shared_upload_link_email.html @@ -8,7 +8,7 @@

{% trans "Hi," %}

-{% blocktrans %}You're receiving this e-mail because {{ email }} has shared an upload link to you on {{ site_name }}.{% endblocktrans%} +{% blocktrans %}{{ email }} shared an upload link to you on {{ site_name }}.{% endblocktrans%}

diff --git a/seahub/templates/sysadmin/user_activation_email.html b/seahub/templates/sysadmin/user_activation_email.html new file mode 100644 index 0000000000..a6ce48ad09 --- /dev/null +++ b/seahub/templates/sysadmin/user_activation_email.html @@ -0,0 +1,19 @@ +{% extends 'email_base.html' %} + +{% load i18n %} + +{% block email_con %} + +{% autoescape off %} + +

{% trans "Hi," %}

+ +

+{% blocktrans %}Your account {{ username }} on {{ site_name }} has been activated.{% endblocktrans %} +

+ +{% trans "Log In" %} + +{% endautoescape %} + +{% endblock %} diff --git a/seahub/templates/sysadmin/user_activation_email.txt b/seahub/templates/sysadmin/user_activation_email.txt deleted file mode 100644 index 56ca2b5dab..0000000000 --- a/seahub/templates/sysadmin/user_activation_email.txt +++ /dev/null @@ -1,10 +0,0 @@ -{% load i18n %}{% blocktrans %}You're receiving this e-mail because your account on {{site_name}} is activated by site admin.{% endblocktrans %} - -{% trans "Please click the following link to log in:" %} -{{login_url}} - -{% trans "Your username, in case you've forgotten:" %} {{ username }} - -{% trans "Thanks for using our site!" %} - -{% blocktrans %}The {{ site_name }} team{% endblocktrans %} diff --git a/seahub/templates/sysadmin/user_activation_email_subject.txt b/seahub/templates/sysadmin/user_activation_email_subject.txt deleted file mode 100644 index 7cfe762ed7..0000000000 --- a/seahub/templates/sysadmin/user_activation_email_subject.txt +++ /dev/null @@ -1 +0,0 @@ -{% load i18n %}{% blocktrans %}Your account on {{site_name}} is activated{% endblocktrans %} diff --git a/seahub/templates/sysadmin/user_add_email.html b/seahub/templates/sysadmin/user_add_email.html index 3638fdec2f..3398f4e70f 100644 --- a/seahub/templates/sysadmin/user_add_email.html +++ b/seahub/templates/sysadmin/user_add_email.html @@ -10,22 +10,19 @@

{% if org %} -{% blocktrans with org_name=org.org_name %}You're receiving this e-mail because {{ user }} added you to organization "{{ org_name }}" on {{ site_name }}.{% endblocktrans%} +{% blocktrans with org_name=org.org_name %}{{ user }} invited you to join organization "{{ org_name }}" on {{ site_name }}.{% endblocktrans%} {% else %} -{% blocktrans %}You're receiving this e-mail because {{ user }} added you to {{ site_name }}.{% endblocktrans%} +{% blocktrans %}{{ user }} invited you to join {{ site_name }}.{% endblocktrans%} {% endif %}

-{% trans "Following is your account information:" %}
+{% trans "Here is your account information:" %}
{% blocktrans %}Email: {{ email }}{% endblocktrans %}
-{% blocktrans %}Password: {{ password }}{% endblocktrans %} +{% blocktrans %}Password: {{ password }}{% endblocktrans %}

-

-{% trans "Please go to the following page and log in:" %}
-{{ protocol }}://{{ domain }}{% url 'auth_login' %} -

+{% trans "Log In" %} {% endautoescape %} diff --git a/seahub/templates/sysadmin/user_reset_email.html b/seahub/templates/sysadmin/user_reset_email.html index dbe1923128..73f197a28f 100644 --- a/seahub/templates/sysadmin/user_reset_email.html +++ b/seahub/templates/sysadmin/user_reset_email.html @@ -9,11 +9,7 @@

{% trans "Hi," %}

-{% blocktrans %}You're receiving this e-mail because staff has reset your password at {{ site_name }}. {% endblocktrans %} -

- -

-{% blocktrans %}Your new password is {{ password }}, please modify your password as soon as possible.{% endblocktrans %} +{% blocktrans %}Your password on {{ site_name }} has been reset. Now it is {{ password }}. Please change it as soon as possible. {% endblocktrans %}

{% endautoescape %} diff --git a/seahub/views/__init__.py b/seahub/views/__init__.py index 28303151e4..6eb2875769 100644 --- a/seahub/views/__init__.py +++ b/seahub/views/__init__.py @@ -18,7 +18,6 @@ from urllib import quote from django.core.cache import cache from django.core.urlresolvers import reverse -from django.core.mail import send_mail from django.contrib import messages from django.contrib.sites.models import Site, RequestSite from django.db import IntegrityError diff --git a/seahub/views/sysadmin.py b/seahub/views/sysadmin.py index db841d2f4c..12ef117c08 100644 --- a/seahub/views/sysadmin.py +++ b/seahub/views/sysadmin.py @@ -33,7 +33,7 @@ from seahub.share.models import FileShare import seahub.settings as settings from seahub.settings import INIT_PASSWD, \ SEND_EMAIL_ON_ADDING_SYSTEM_MEMBER, SEND_EMAIL_ON_RESETTING_USER_PASSWD -from seahub.utils import get_site_scheme_and_netloc +from seahub.utils import get_site_scheme_and_netloc, get_service_url logger = logging.getLogger(__name__) @@ -407,20 +407,21 @@ def user_deactivate(request, user_id): def email_user_on_activation(user): """Send an email to user when admin activate his/her account. """ - ctx_dict = { - "site_name": settings.SITE_NAME, - "login_url": "%s%s" % (get_site_scheme_and_netloc(), - reverse('auth_login')), - "username": user.email, + service_url = get_service_url() + site_name = settings.SITE_NAME + + t = loader.get_template('sysadmin/user_activation_email.html') + c = { + 'site_name': site_name, + 'media_url': settings.MEDIA_URL, + 'logo_path': settings.LOGO_PATH, + 'service_url': service_url, + 'username': user.email, } - subject = render_to_string('sysadmin/user_activation_email_subject.txt', - ctx_dict) - # Email subject *must not* contain newlines - subject = ''.join(subject.splitlines()) - - message = render_to_string('sysadmin/user_activation_email.txt', ctx_dict) - - user.email_user(subject, message, settings.DEFAULT_FROM_EMAIL) + msg = EmailMessage(_(u'Your account on s% is activated') % site_name, t.render(Context(c)), + None, [user.email]) + msg.content_subtype = "html" + msg.send() @login_required @sys_staff_required @@ -459,22 +460,19 @@ def send_user_reset_email(request, email, password): Send email when reset user password. """ - use_https = request.is_secure() - domain = RequestSite(request).domain + service_url = get_service_url() + site_name = settings.SITE_NAME t = loader.get_template('sysadmin/user_reset_email.html') c = { 'email': email, 'password': password, - 'site_name': settings.SITE_NAME, - 'media_url': settings.MEDIA_URL, - 'logo_path': settings.LOGO_PATH, - 'domain': domain, - 'protocol': use_https and 'https' or 'http', + 'site_name': site_name, 'media_url': settings.MEDIA_URL, 'logo_path': settings.LOGO_PATH, + 'service_url': service_url, } - msg = EmailMessage(_(u'Password Reset'), t.render(Context(c)), + msg = EmailMessage(_(u'Password has been reset on %s') % site_name, t.render(Context(c)), None, [email]) msg.content_subtype = "html" msg.send() @@ -519,22 +517,21 @@ def user_reset(request, user_id): def send_user_add_mail(request, email, password): """Send email when add new user.""" - use_https = request.is_secure() - domain = RequestSite(request).domain - + service_url = get_service_url() + site_name = settings.SITE_NAME + t = loader.get_template('sysadmin/user_add_email.html') c = { 'user': request.user.username, 'org': request.user.org, 'email': email, 'password': password, - 'domain': domain, - 'protocol': use_https and 'https' or 'http', - 'site_name': settings.SITE_NAME, + 'service_url': service_url, + 'site_name': site_name, 'media_url': settings.MEDIA_URL, 'logo_path': settings.LOGO_PATH, } - msg = EmailMessage(_(u'Seafile Registration Information'), t.render(Context(c)), + msg = EmailMessage(_(u'You are invited to join %s') % site_name, t.render(Context(c)), None, [email]) msg.content_subtype = "html" msg.send()