diff --git a/seahub/auth/forms.py b/seahub/auth/forms.py index 3c61503d63..05f4ed5b22 100644 --- a/seahub/auth/forms.py +++ b/seahub/auth/forms.py @@ -11,6 +11,8 @@ from seahub.utils import IS_EMAIL_CONFIGURED from captcha.fields import CaptchaField +import seahub.settings as settings + class AuthenticationForm(forms.Form): """ Base class for authenticating users. Extend this to get a form that accepts @@ -84,7 +86,6 @@ class PasswordResetForm(forms.Form): """ Generates a one-use only link for resetting password and sends to the user """ - #from django.core.mail import send_mail from django.core.mail import EmailMessage user = self.users_cache @@ -104,6 +105,8 @@ class PasswordResetForm(forms.Form): 'user': user, 'token': token_generator.make_token(user), 'protocol': use_https and 'https' or 'http', + 'media_url': settings.MEDIA_URL, + 'logo_path': settings.LOGO_PATH, } msg = EmailMessage(_("Password reset on %s") % site_name, diff --git a/seahub/share/views.py b/seahub/share/views.py index 4830307dc7..51f9330d40 100644 --- a/seahub/share/views.py +++ b/seahub/share/views.py @@ -2,7 +2,7 @@ import os import logging import simplejson as json -from django.core.mail import send_mail +from django.core.mail import EmailMessage from django.core.urlresolvers import reverse from django.db import IntegrityError from django.http import HttpResponse, HttpResponseRedirect, Http404, \ @@ -39,6 +39,7 @@ from seahub.utils import render_permission_error, string2list, render_error, \ gen_file_share_link, IS_EMAIL_CONFIGURED, check_filename_with_rename, \ get_repo_last_modify, is_valid_username +import seahub.settings as settings try: from seahub.settings import CLOUD_MODE except ImportError: @@ -799,17 +800,24 @@ 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 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', + 'media_url': settings.MEDIA_URL, + 'logo_path': settings.LOGO_PATH, } try: - send_mail(_(u'Your friend shared a file to you on Seafile'), - t.render(Context(c)), None, [to_email], - fail_silently=False) + msg = EmailMessage(_(u'Your friend shared a file to you on Seafile'), + t.render(Context(c)), None, [to_email]) + msg.content_subtype = "html" + msg.send() except Exception, e: logger.error(str(e)) data = json.dumps({'error':_(u'Internal server error. Send failed.')}) @@ -1073,17 +1081,25 @@ 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 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', + 'media_url': settings.MEDIA_URL, + 'logo_path': settings.LOGO_PATH, } try: - send_mail(_(u'Your friend shared a upload link to you on Seafile'), - t.render(Context(c)), None, [to_email], - fail_silently=False) + msg = EmailMessage(_(u'Your friend shared a upload link to you on Seafile'), + t.render(Context(c)), None, [to_email]) + msg.content_subtype = "html" + msg.send() except Exception, e: logger.error(str(e)) data = json.dumps({'error':_(u'Internal server error. Send failed.')}) diff --git a/seahub/templates/email_base.html b/seahub/templates/email_base.html index f241481626..64783187f5 100644 --- a/seahub/templates/email_base.html +++ b/seahub/templates/email_base.html @@ -1,8 +1,17 @@ +{% load i18n %}
+ {% trans "Thanks for using our site!" %} +
+ ++ {% blocktrans %}The {{ site_name }} team{% endblocktrans %} +
-{% trans "Thanks for using our site!" %} -
- --{% blocktrans %}The {{ site_name }} team{% endblocktrans %} -
- {% endautoescape %} {% endblock %} diff --git a/seahub/templates/shared_link_email.html b/seahub/templates/shared_link_email.html index 4584245cf6..c1b4f4b808 100644 --- a/seahub/templates/shared_link_email.html +++ b/seahub/templates/shared_link_email.html @@ -1,11 +1,22 @@ -{% load i18n %}{% autoescape off %} +{% extends 'email_base.html' %} + +{% load i18n %} + +{% block email_con %} + +{% autoescape off %} + +{% 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:" %} +
+{% trans "Please go to the following page and view the file:" %}
{{ file_shared_link }}
-
-{% trans "Thanks for using our site!" %}
-
-{% blocktrans %}The {{ site_name }} team{% endblocktrans %}
+
{% trans "Hi," %}
+ +{% blocktrans %}You're receiving this e-mail because {{ email }} has shared an upload link to you on {{ site_name }}.{% endblocktrans%} +
-{% trans "You can go to the following page and upload your files:" %} +
+{% trans "You can go to the following page and upload your files:" %}
{{ shared_upload_link }}
-
-{% trans "Thanks for using our site!" %}
-
-{% blocktrans %}The {{ site_name }} team{% endblocktrans %}
+
{% trans "Hi," %}
+ +{% 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%} {% else %} {% blocktrans %}You're receiving this e-mail because {{ user }} added you to {{ site_name }}.{% endblocktrans%} {% endif %} +
-{% trans "Following is your account information:" %} -{% blocktrans %}Email: {{ email }}{% endblocktrans %} +
+{% trans "Following is your account information:" %}
+{% blocktrans %}Email: {{ email }}{% endblocktrans %}
{% blocktrans %}Password: {{ password }}{% endblocktrans %}
+
+{% trans "Please go to the following page and log in:" %}
{{ protocol }}://{{ domain }}{% url 'auth_login' %}
-
-{% trans "Thanks for using our site!" %}
-
-{% blocktrans %}The {{ site_name }} team{% endblocktrans %}
+
{% 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 %} - -{% trans "Thanks for using our site!" %} - -{% blocktrans %}The {{ site_name }} team{% endblocktrans %} +
{% endautoescape %} + +{% endblock %} diff --git a/seahub/views/sysadmin.py b/seahub/views/sysadmin.py index a6a85acb7e..db841d2f4c 100644 --- a/seahub/views/sysadmin.py +++ b/seahub/views/sysadmin.py @@ -6,7 +6,7 @@ import logging import simplejson as json from django.core.urlresolvers import reverse -from django.core.mail import send_mail +from django.core.mail import EmailMessage from django.contrib import messages from django.http import HttpResponse, Http404, HttpResponseRedirect from django.shortcuts import render_to_response @@ -459,14 +459,25 @@ def send_user_reset_email(request, email, password): Send email when reset user password. """ + use_https = request.is_secure() + domain = RequestSite(request).domain + 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', + 'media_url': settings.MEDIA_URL, + 'logo_path': settings.LOGO_PATH, } - send_mail(_(u'Password Reset'), t.render(Context(c)), - None, [email], fail_silently=False) + msg = EmailMessage(_(u'Password Reset'), t.render(Context(c)), + None, [email]) + msg.content_subtype = "html" + msg.send() @login_required @sys_staff_required @@ -520,9 +531,14 @@ def send_user_add_mail(request, email, password): 'domain': domain, 'protocol': use_https and 'https' or 'http', 'site_name': settings.SITE_NAME, + 'media_url': settings.MEDIA_URL, + 'logo_path': settings.LOGO_PATH, } - send_mail(_(u'Seafile Registration Information'), t.render(Context(c)), - None, [email], fail_silently=False) + msg = EmailMessage(_(u'Seafile Registration Information'), t.render(Context(c)), + None, [email]) + msg.content_subtype = "html" + msg.send() + @login_required def user_add(request):