diff --git a/cms/envs/common.py b/cms/envs/common.py index e9871260a6..556bb857be 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -94,6 +94,8 @@ from lms.envs.common import ( HELP_TOKENS_BOOKS, SUPPORT_SITE_LINK, + + CONTACT_EMAIL, ) from path import Path as path from warnings import simplefilter diff --git a/common/djangoapps/student/tests/test_email.py b/common/djangoapps/student/tests/test_email.py index eaf76880e1..88c4183800 100644 --- a/common/djangoapps/student/tests/test_email.py +++ b/common/djangoapps/student/tests/test_email.py @@ -6,7 +6,7 @@ import mock from student.tests.factories import UserFactory, RegistrationFactory, PendingEmailChangeFactory from student.views import ( reactivation_email_for_user, do_email_change_request, confirm_email_change, - validate_new_email, SETTING_CHANGE_INITIATED + validate_new_email, SETTING_CHANGE_INITIATED, generate_activation_email_context ) from student.models import UserProfile, PendingEmailChange, Registration from third_party_auth.views import inactive_user_view @@ -72,16 +72,16 @@ class EmailTestMixin(object): class ActivationEmailTests(TestCase): """Test sending of the activation email. """ - ACTIVATION_SUBJECT = u"Activate Your {} Account".format(settings.PLATFORM_NAME) + ACTIVATION_SUBJECT = u"Action Required: Activate your {} account".format(settings.PLATFORM_NAME) # Text fragments we expect in the body of an email # sent from an OpenEdX installation. OPENEDX_FRAGMENTS = [ - u"Thank you for creating an account with {platform}!".format(platform=settings.PLATFORM_NAME), + u"high-quality {platform} courses".format(platform=settings.PLATFORM_NAME), "http://edx.org/activate/", ( - "Check the help section of the " - u"{platform} website".format(platform=settings.PLATFORM_NAME) + "please use our web form at " + u"{support_url} ".format(support_url=settings.SUPPORT_SITE_LINK) ) ] @@ -170,10 +170,7 @@ class ReactivationEmailTests(EmailTestMixin, TestCase): def assertReactivateEmailSent(self, email_user): """Assert that the correct reactivation email has been sent""" - context = { - 'name': self.user.profile.name, - 'key': self.registration.activation_key - } + context = generate_activation_email_context(self.user, self.registration) self.assertEmailUser( email_user, diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index c943a3b6f8..f15aec4547 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -583,6 +583,24 @@ def is_course_blocked(request, redeemed_registration_codes, course_key): return blocked +def generate_activation_email_context(user, registration): + """ + Constructs a dictionary for use in activation email contexts + + Arguments: + user (User): Currently logged-in user + registration (Registration): Registration object for the currently logged-in user + """ + return { + 'name': user.profile.name, + 'key': registration.activation_key, + 'lms_url': configuration_helpers.get_value('LMS_ROOT_URL', settings.LMS_ROOT_URL), + 'platform_name': configuration_helpers.get_value('PLATFORM_NAME', settings.PLATFORM_NAME), + 'support_url': configuration_helpers.get_value('SUPPORT_SITE_LINK', settings.SUPPORT_SITE_LINK), + 'support_email': configuration_helpers.get_value('CONTACT_EMAIL', settings.CONTACT_EMAIL), + } + + def compose_and_send_activation_email(user, profile, user_registration=None): """ Construct all the required params and send the activation email @@ -596,10 +614,7 @@ def compose_and_send_activation_email(user, profile, user_registration=None): dest_addr = user.email if user_registration is None: user_registration = Registration.objects.get(user=user) - context = { - 'name': profile.name, - 'key': user_registration.activation_key, - } + context = generate_activation_email_context(user, user_registration) subject = render_to_string('emails/activation_email_subject.txt', context) # Email subject *must not* contain newlines subject = ''.join(subject.splitlines()) @@ -2484,7 +2499,7 @@ def password_reset_confirm_wrapper(request, uidb36=None, token=None): def reactivation_email_for_user(user): try: - reg = Registration.objects.get(user=user) + registration = Registration.objects.get(user=user) except Registration.DoesNotExist: return JsonResponse({ "success": False, @@ -2492,10 +2507,7 @@ def reactivation_email_for_user(user): }) # TODO: this should be status code 400 # pylint: disable=fixme try: - context = { - 'name': user.profile.name, - 'key': reg.activation_key, - } + context = generate_activation_email_context(user, registration) except ObjectDoesNotExist: log.error( u'Unable to send reactivation email due to unavailable profile for the user "%s"', @@ -2511,6 +2523,7 @@ def reactivation_email_for_user(user): subject = ''.join(subject.splitlines()) message = render_to_string('emails/activation_email.txt', context) from_address = configuration_helpers.get_value('email_from_address', settings.DEFAULT_FROM_EMAIL) + from_address = configuration_helpers.get_value('ACTIVATION_EMAIL_FROM_ADDRESS', from_address) try: user.email_user(subject, message, from_address) diff --git a/lms/envs/aws.py b/lms/envs/aws.py index 3234644df9..d7b8a74f6f 100644 --- a/lms/envs/aws.py +++ b/lms/envs/aws.py @@ -234,6 +234,9 @@ PRESS_EMAIL = ENV_TOKENS.get('PRESS_EMAIL', PRESS_EMAIL) CONTACT_MAILING_ADDRESS = ENV_TOKENS.get('CONTACT_MAILING_ADDRESS', CONTACT_MAILING_ADDRESS) +# Account activation email sender address +ACTIVATION_EMAIL_FROM_ADDRESS = ENV_TOKENS.get('ACTIVATION_EMAIL_FROM_ADDRESS', ACTIVATION_EMAIL_FROM_ADDRESS) + # Currency PAID_COURSE_REGISTRATION_CURRENCY = ENV_TOKENS.get('PAID_COURSE_REGISTRATION_CURRENCY', PAID_COURSE_REGISTRATION_CURRENCY) diff --git a/lms/envs/common.py b/lms/envs/common.py index f75f354cb3..c711197190 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -838,6 +838,9 @@ FINANCE_EMAIL = '' # Platform mailing address CONTACT_MAILING_ADDRESS = '' +# Account activation email sender address +ACTIVATION_EMAIL_FROM_ADDRESS = '' + ADMINS = () MANAGERS = ADMINS diff --git a/lms/envs/test.py b/lms/envs/test.py index 14bb689872..bbf519ff05 100644 --- a/lms/envs/test.py +++ b/lms/envs/test.py @@ -443,6 +443,7 @@ MICROSITE_CONFIGURATION = { "platform_name": "Test Site", "logo_image_url": "test_site/images/header-logo.png", "email_from_address": "test_site@edx.org", + "ACTIVATION_EMAIL_FROM_ADDRESS": "test_activate@edx.org", "payment_support_email": "test_site@edx.org", "ENABLE_MKTG_SITE": False, "SITE_NAME": "test_site.localhost", @@ -474,6 +475,7 @@ MICROSITE_CONFIGURATION = { "platform_name": "Test logistration", "logo_image_url": "test_site/images/header-logo.png", "email_from_address": "test_site@edx.org", + "ACTIVATION_EMAIL_FROM_ADDRESS": "test_activate@edx.org", "payment_support_email": "test_site@edx.org", "ENABLE_MKTG_SITE": False, "ENABLE_COMBINED_LOGIN_REGISTRATION": True, @@ -596,3 +598,5 @@ LMS_ROOT_URL = "http://localhost:8000" ECOMMERCE_API_URL = 'https://ecommerce.example.com/api/v2/' ENTERPRISE_API_URL = 'http://enterprise.example.com/enterprise/api/v1/' + +ACTIVATION_EMAIL_FROM_ADDRESS = 'test_activate@edx.org' diff --git a/lms/templates/emails/activation_email.txt b/lms/templates/emails/activation_email.txt index 66670f9d47..670875c4cc 100644 --- a/lms/templates/emails/activation_email.txt +++ b/lms/templates/emails/activation_email.txt @@ -1,22 +1,23 @@ <%! from django.utils.translation import ugettext as _ %> -<%! from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers %> -${_("Thank you for creating an account with {platform_name}!").format( - platform_name=configuration_helpers.get_value('PLATFORM_NAME', settings.PLATFORM_NAME) -)} - -${_("There's just one more step before you can enroll in a course: " - "you need to activate your {platform_name} account. To activate " - "your account, click the following link. If that doesn't work, " - "copy and paste the link into your browser's address bar.").format( - platform_name=configuration_helpers.get_value('PLATFORM_NAME', settings.PLATFORM_NAME) - )} +${_("You're almost there! Use the link to activate your account to access engaging, high-quality " +"{platform_name} courses. Note that you will not be able to log back into your account until " +"you have activated it.").format(platform_name=platform_name)} % if is_secure: https://${ site }/activate/${ key } % else: http://${ site }/activate/${ key } % endif -${_("If you didn't create an account, you don't need to do anything; you " - "won't receive any more email from us. If you need assistance, please " - "do not reply to this email message. Check the help section of the " - "{platform_name} website.").format(platform_name=configuration_helpers.get_value('PLATFORM_NAME', settings.PLATFORM_NAME))} + +${_("Enjoy learning with {platform_name}.").format(platform_name=platform_name)} + +${_("The {platform_name} Team").format(platform_name=platform_name)} + +${_("If you need help, please use our web form at {support_url} or email {support_email}.").format( + support_url=support_url, support_email=support_email +)} + +${_("This email message was automatically sent by {lms_url} because someone attempted to create an " +"account on {platform_name} using this email address.").format( + lms_url=lms_url, platform_name=platform_name +)} \ No newline at end of file diff --git a/lms/templates/emails/activation_email_subject.txt b/lms/templates/emails/activation_email_subject.txt index a83900a7c1..cdb52fe458 100644 --- a/lms/templates/emails/activation_email_subject.txt +++ b/lms/templates/emails/activation_email_subject.txt @@ -1,6 +1,2 @@ <%! from django.utils.translation import ugettext as _ %> -<%! from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers %> - -${_("Activate Your {platform_name} Account").format( - platform_name=configuration_helpers.get_value('PLATFORM_NAME', settings.PLATFORM_NAME -))} +${_("Action Required: Activate your {platform_name} account").format(platform_name=platform_name)} diff --git a/openedx/core/djangoapps/user_api/tests/test_helpers.py b/openedx/core/djangoapps/user_api/tests/test_helpers.py index 903a79af14..00576d588e 100644 --- a/openedx/core/djangoapps/user_api/tests/test_helpers.py +++ b/openedx/core/djangoapps/user_api/tests/test_helpers.py @@ -53,6 +53,7 @@ class InterceptErrorsTest(TestCase): @mock.patch('openedx.core.djangoapps.user_api.helpers.LOGGER') def test_logs_errors(self, mock_logger): + self.maxDiff = None exception = 'openedx.core.djangoapps.user_api.tests.test_helpers.FakeInputException' expected_log_msg = ( u"An unexpected error occurred when calling 'intercepted_function' with arguments '()' and " diff --git a/openedx/core/djangoapps/user_api/tests/test_views.py b/openedx/core/djangoapps/user_api/tests/test_views.py index 10f0fa2685..e4f4f0267e 100644 --- a/openedx/core/djangoapps/user_api/tests/test_views.py +++ b/openedx/core/djangoapps/user_api/tests/test_views.py @@ -1625,10 +1625,10 @@ class RegistrationViewTest(ThirdPartyAuthTestMixin, UserAPITestCase): self.assertEqual(sent_email.to, [self.EMAIL]) self.assertEqual( sent_email.subject, - u"Activate Your {platform} Account".format(platform=settings.PLATFORM_NAME) + u"Action Required: Activate your {platform} account".format(platform=settings.PLATFORM_NAME) ) self.assertIn( - u"you need to activate your {platform} account".format(platform=settings.PLATFORM_NAME), + u"high-quality {platform} courses".format(platform=settings.PLATFORM_NAME), sent_email.body )