How to setup smtp email in production

I have installed juniper.master on aws following the instructions in this blog: Open edX Step-By-Step Production Installation Guide - Blog
Everything is up and running,except for the email sending.
I am not getting emails during signup and reset password.
What I’ve done:

  1. Edited the following properties inside lms.env.json and cms.env.json files, and set my email adress where emails are required( eg:- “DEFAULT_FEEDBACK_EMAIL”: “myaccount@gmail.com”,)

    “EMAIL_BACKEND”: “django.core.mail.backends.smtp.EmailBackend”,
    “EMAIL_HOST”: “smtp.gmail.com”,
    “EMAIL_PORT”: 587,
    “EMAIL_USE_TLS”: true,
  2. Edited the following properties inside lms.auth.json and cms.auth.json files
    “EMAIL_HOST_PASSWORD”: “emailpassword”,
    “EMAIL_HOST_USER”: “myaccount@gmail.com”,
  3. I restarted open edx
    /edx/bin/supervisorctl restart lms
    /edx/bin/supervisorctl restart cms
    /edx/bin/supervisorctl restart edxapp_worker:

Am i missing something here?
Thanks in advance for your help!

:warning: 2022/11/18 ADMINISTRATOR UPDATE The above instructions are wrong when running Open edX with Tutor, and so is the proposed solution. Instead, users are encouraged to read the following tutorial: Using Google Mail as an SMTP server — Tutor documentation This topic is preserved for historical purposed only.

This issue was resolved by editing the same properties inside /edx/etc/lms.yml file

2 Likes

But the activation email is providing a broken account activation link that points to “http://localhost”.
In my configuration file in /edx/app/edxapp/lms.env.json, as well edx/etc/lms.yml , I have these

“LMS_BASE”: “www.domain.com”,
“LMS_INTERNAL_ROOT_URL”: “www.domain.com”,
“LMS_ROOT_URL”: “www.domain.com”,

Any ideas?

Thanks in advance!

2 options:

1- in your site_configuration, in LMS Django Admin, check that you have “lms_root_url”:“http://www.domain.com , and edit the file “lms/templates/emails/activation_email.txt”, change “lms_url” by “lms_root_url

2- just go and edit the file “lms/templates/emails/activation_email.txt”, change “lms_url” by “LMS_ROOT_URL

Restart all services, and try again.

That’s how i fixed it.

Regards,

1 Like

Thanks @Herve_siyou . site name was not filled on lms.env.json and cms.env.json files.When I correct that, the problem was fixed.
Your solutions are also correct.

1 Like

(for JUNIPER release)
Edited the following properties inside /edx/etc/lms.yml and /edx/etc/studio.yml
(Used AWS SES for email)

“DEFAULT_FROM_EMAIL”: “myaccount@gmail.com”,
“EMAIL_BACKEND”: “django.core.mail.backends.smtp.EmailBackend”,
“EMAIL_HOST”: “smtp.gmail.com”,
“EMAIL_PORT”: 587,
“EMAIL_USE_TLS”: true,
“EMAIL_HOST_PASSWORD”: “emailpassword”,
“EMAIL_HOST_USER”: “myaccount@gmail.com”,

Restarted open edx -
/edx/bin/supervisorctl restart lms cms edxapp_worker:

Hi @Himanshu_Pandit

You mentioned: “Edited the following properties inside /edx/etc/lms.yml and /edx/etc/studio.yml”
Could you help me locate the files?
I cannot find them anywhere within my tree directory. I installed the open Edx using “tutor local quickstart” and now I am trying to configure it but I cannot find the path /edx/ at all. where is it?

Thanks in advance
Radek

In tutor… yow have to change settings in lms.env.json and cms.env.json…
location:–
/root/.local/share/tutor/env/apps/openedx/config/

“DEFAULT_FROM_EMAIL”: “myaccount@gmail.com”,
“EMAIL_BACKEND”: “django.core.mail.backends.smtp.EmailBackend”,
“EMAIL_HOST”: “smtp.gmail.com”,
“EMAIL_PORT”: 587,
“EMAIL_USE_TLS”: true,
“EMAIL_HOST_PASSWORD”: “emailpassword”,
“EMAIL_HOST_USER”: “myaccount@gmail.com”,
1 Like

Thank you very much. That helped a lot!

1 Like

This solution fixed my problem. Thank u very much😊


I change this… Am I right or wrong?

lms_url=LMS_ROOT_URL

Yes it’s right

1 Like

Mar 28 15:47:46 Edx-VM [service_variant=lms][audit][env:sandbox] INFO [Edx-VM 21267] [register.py:211] - Login success on new account creation - DawThinThinSoe1
Mar 28 15:47:46 Edx-VM [service_variant=lms][openedx.core.djangoapps.catalog.utils][env:sandbox] WARNING [Edx-VM 21294] [utils.py:103] - Failed to get program UUIDs from the cache for site www.knowledgehub.edu.mm.
Mar 28 15:47:47 Edx-VM [service_variant=lms][edx.celery.task][env:sandbox] ERROR [Edx-VM 26652] [tasks.py:48] - Unable to send activation email to user from “registration@example.com” to “thinthinsoe.geo@gmail.com
Traceback (most recent call last):
File “/edx/app/edxapp/edx-platform/common/djangoapps/student/tasks.py”, line 23, in send_activation_email
mail.send_mail(subject, message, from_address, [dest_addr], fail_silently=False)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/mail/init.py”, line 62, in send_mail
return mail.send()
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/mail/message.py”, line 348, in send
return self.get_connection(fail_silently).send_messages([self])
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/mail/backends/smtp.py”, line 104, in send_messages
new_conn_created = self.open()
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/mail/backends/smtp.py”, line 71, in open
self.connection.login(force_str(self.username), force_str(self.password))
File “/usr/lib/python2.7/smtplib.py”, line 622, in login
raise SMTPAuthenticationError(code, resp)
SMTPAuthenticationError: (534, ‘5.7.14 <Sign in - Google Accounts B1VDMpkd0hgcVyREaiaU1u_eNbEFzNtix9AQ68qWx7SGYLYTX5px7F7JMEn7B4dRpcVEk\n5.7.14 G-vY42NVB2-42_3lpEfolr7pj3lXRydKiwmQYsnla86UU2cQSyZ6ggZmlfCZLu9M>\n5.7.14 Please log in via your web browser and then try again.\n5.7.14 Learn more at\n5.7.14 Check Gmail through other email platforms - Gmail Help h10-20020a056a00230a00b004faa0f67c3esm16065361pfh.23 - gsmtp’)
Mar 28 15:47:47 Edx-VM [service_variant=lms][celery.worker.job][env:sandbox] ERROR [Edx-VM 21346] [log.py:282] - Task student.tasks.send_activation_email[28b8df38-8766-492e-98b3-942f26bb541a] raised unexpected: Exception()
Traceback (most recent call last):
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/celery/app/trace.py”, line 240, in trace_task
R = retval = fun(*args, **kwargs)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/celery/app/trace.py”, line 438, in protected_call
return self.run(*args, **kwargs)
File “/edx/app/edxapp/edx-platform/common/djangoapps/student/tasks.py”, line 50, in send_activation_email
raise Exception

I change lms root url but it doesn’t work at my server. That is error log for activation link. pls check and help me…

This is a raise SMTPAuthenticationError, so verify first that you properly configure the mail account in /edx/etc/lms.yml and studio.yml (or in lms.env.json and cms.env.json) :

“EMAIL_HOST”: smtp.gmail.com,
“EMAIL_PORT”: 587,
“EMAIL_USE_TLS”: true,
“DEFAULT_FROM_EMAIL”: ‘yourgmail@gmail.com’,
“EMAIL_HOST_PASSWORD”: “mypassword”,
“EMAIL_HOST_USER”: “yourgmail@gmail.com”,

Restart service:

/edx/bin/supervisorctl restart cms
/edx/bin/supervisorctl restart lms

and try again

“DEFAULT_FROM_EMAIL”: ‘yourgmail@gmail.com’,
“EMAIL_HOST_PASSWORD”: “mypassword”,
“EMAIL_HOST_USER”: “yourgmail@gmail.com”,
I do not see these three lines are in both LMS/cms env.json files.

“EMAIL_HOST_PASSWORD”: “mypassword”,
“EMAIL_HOST_USER”: “yourgmail@gmail.com”,
I see only these two lines in lms.auth.json

I have already configured my Gmail acc on these related files. What should I do?

“DEFAULT_FROM_EMAIL”: ‘yourgmail@gmail.com’,


I add this line to lms.env.json and cms.env.json. But It doesn’t send activation mail to user. How can I do?pls

Mar 30 13:25:00 Edx-VM [service_variant=lms][openedx.core.djangoapps.catalog.utils][env:sandbox] WARNING [Edx-VM 21846] [utils.py:103] - Failed to get program UUIDs from the cache for site www.knowledgehub.edu.mm.
Mar 30 13:25:11 Edx-VM [service_variant=lms][audit][env:sandbox] INFO [Edx-VM 21851] [models.py:2245] - Login success - user.id: 3848
Mar 30 13:25:11 Edx-VM [service_variant=lms][root][env:sandbox] ERROR [Edx-VM 21851] [signals.py:21] - Uncaught exception from None
Traceback (most recent call last):
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/handlers/exception.py”, line 41, in inner
response = get_response(request)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/handlers/base.py”, line 249, in _legacy_get_response
response = self._get_response(request)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/handlers/base.py”, line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/handlers/base.py”, line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/views/decorators/csrf.py”, line 58, in wrapped_view
return view_func(*args, **kwargs)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/views/generic/base.py”, line 68, in view
return self.dispatch(request, *args, **kwargs)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/decorators.py”, line 67, in _wrapper
return bound_func(*args, **kwargs)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/decorators.py”, line 63, in bound_func
return func.get(self, type(self))(*args2, **kwargs2)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/decorators.py”, line 67, in _wrapper
return bound_func(*args, **kwargs)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/views/decorators/debug.py”, line 76, in sensitive_post_parameters_wrapper
return view(request, *args, **kwargs)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/decorators.py”, line 63, in bound_func
return func.get(self, type(self))(*args2, **kwargs2)
File “/edx/app/edxapp/edx-platform/openedx/core/djangoapps/user_api/views.py”, line 179, in dispatch
return super(RegistrationView, self).dispatch(request, *args, **kwargs)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/rest_framework/views.py”, line 489, in dispatch
response = self.handle_exception(exc)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/rest_framework/views.py”, line 449, in handle_exception
self.raise_uncaught_exception(exc)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/rest_framework/views.py”, line 486, in dispatch
response = handler(request, *args, **kwargs)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/decorators.py”, line 67, in _wrapper
return bound_func(*args, **kwargs)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/views/decorators/csrf.py”, line 58, in wrapped_view
return view_func(*args, **kwargs)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/decorators.py”, line 63, in bound_func
return func.get(self, type(self))(*args2, **kwargs2)
File “/edx/app/edxapp/edx-platform/openedx/core/djangoapps/user_api/views.py”, line 154, in post
user = create_account_with_params(request, data)
File “/edx/app/edxapp/edx-platform/openedx/core/djangoapps/user_authn/views/register.py”, line 182, in create_account_with_params
compose_and_send_activation_email(user, profile, registration)
File “/edx/app/edxapp/edx-platform/common/djangoapps/student/views/management.py”, line 206, in compose_and_send_activation_email
message_for_activation = render_to_string(‘emails/activation_email.txt’, context)
File “/edx/app/edxapp/edx-platform/common/djangoapps/edxmako/shortcuts.py”, line 159, in render_to_string
return template.render(dictionary, request)
File “/edx/app/edxapp/edx-platform/common/djangoapps/edxmako/template.py”, line 59, in render
return self.mako_template.render_unicode(**context_dictionary)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/template.py”, line 454, in render_unicode
as_unicode=True)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/runtime.py”, line 829, in _render
**kwargs_for_callable(callable, data))
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/runtime.py”, line 864, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/runtime.py”, line 890, in exec_template
callable
(context, *args, **kwargs)
File “/tmp/mako_lms/6a8118f6422e51245f4eb827a623ead1/emails/activation_email.txt.py”, line 58, in render_body
lms_url=LMS_ROOT_URL, platform_name=platform_name
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/runtime.py”, line 226, in str
raise NameError(“Undefined”)
NameError: Undefined
Mar 30 13:25:11 Edx-VM [service_variant=lms][django.request][env:sandbox] ERROR [Edx-VM 21851] [exception.py:135] - Internal Server Error: /user_api/v1/account/registration/
Traceback (most recent call last):
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/handlers/exception.py”, line 41, in inner
response = get_response(request)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/handlers/base.py”, line 249, in _legacy_get_response
response = self._get_response(request)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/handlers/base.py”, line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/handlers/base.py”, line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/views/decorators/csrf.py”, line 58, in wrapped_view
return view_func(*args, **kwargs)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/views/generic/base.py”, line 68, in view
return self.dispatch(request, *args, **kwargs)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/decorators.py”, line 67, in _wrapper
return bound_func(*args, **kwargs)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/decorators.py”, line 63, in bound_func
return func.get(self, type(self))(*args2, **kwargs2)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/decorators.py”, line 67, in _wrapper
return bound_func(*args, **kwargs)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/views/decorators/debug.py”, line 76, in sensitive_post_parameters_wrapper
return view(request, *args, **kwargs)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/decorators.py”, line 63, in bound_func
return func.get(self, type(self))(*args2, **kwargs2)
File “/edx/app/edxapp/edx-platform/openedx/core/djangoapps/user_api/views.py”, line 179, in dispatch
return super(RegistrationView, self).dispatch(request, *args, **kwargs)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/rest_framework/views.py”, line 489, in dispatch
response = self.handle_exception(exc)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/rest_framework/views.py”, line 449, in handle_exception
self.raise_uncaught_exception(exc)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/rest_framework/views.py”, line 486, in dispatch
response = handler(request, *args, **kwargs)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/decorators.py”, line 67, in _wrapper
return bound_func(*args, **kwargs)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/views/decorators/csrf.py”, line 58, in wrapped_view
return view_func(*args, **kwargs)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/decorators.py”, line 63, in bound_func
return func.get(self, type(self))(*args2, **kwargs2)
File “/edx/app/edxapp/edx-platform/openedx/core/djangoapps/user_api/views.py”, line 154, in post
user = create_account_with_params(request, data)
File “/edx/app/edxapp/edx-platform/openedx/core/djangoapps/user_authn/views/register.py”, line 182, in create_account_with_params
compose_and_send_activation_email(user, profile, registration)
File “/edx/app/edxapp/edx-platform/common/djangoapps/student/views/management.py”, line 206, in compose_and_send_activation_email
message_for_activation = render_to_string(‘emails/activation_email.txt’, context)
File “/edx/app/edxapp/edx-platform/common/djangoapps/edxmako/shortcuts.py”, line 159, in render_to_string
return template.render(dictionary, request)
File “/edx/app/edxapp/edx-platform/common/djangoapps/edxmako/template.py”, line 59, in render
return self.mako_template.render_unicode(**context_dictionary)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/template.py”, line 454, in render_unicode
as_unicode=True)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/runtime.py”, line 829, in _render
**kwargs_for_callable(callable, data))
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/runtime.py”, line 864, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/runtime.py”, line 890, in exec_template
callable
(context, *args, **kwargs)
File “/tmp/mako_lms/6a8118f6422e51245f4eb827a623ead1/emails/activation_email.txt.py”, line 58, in render_body
lms_url=LMS_ROOT_URL, platform_name=platform_name
File “/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/runtime.py”, line 226, in str
raise NameError(“Undefined”)

Yes exactly, according to your version of OpenEDX!

The error seems to be here, it seems like the key LMS_ROOT_URL is undefined or platform_name: lms_url=LMS_ROOT_URL, platform_name=platform_name

First: verify your siteConfiguration in django Admin, see if you have LMS_ROOT_URL
Second: verify you have set ‘LMS_ROOT_URL’ in lms.env.json and cms.env.json, also verify ‘site_name’ and ‘site_domain’

I’m not sure if the configuration variables are case sensitive…anyway, just check if ‘platform_name’ is exactly writen like this


Do I need to write platform name as my domain name? eg: platform_name= https://…com

No need to do this, ‘platform_name’ should be something like this by default in lms.env.json: “Your Platform Name Here”