Probably the most common issue we hear about Open edX installs is that emails are not being received or go to spam over 90% of the time. This is the nature of operating a mail service on your own server: with so much spam on the internet, there are several measures put in place by email services and other providers to prevent spam. Particularly emails from some mail server on a random AWS instance.
For this reason, it's advisable to sign up for a reliable email service like Sendgrid or Mandrill, and to configure your email to work with this service. This has the added benefit of being able to see email analytics and use a variety of features that come with these services.
Here are steps to set this up with your own Open edX instance:
1. Create an account on a services like Sendgrid or Mandrill
2. Obtain the SMTP server details ie server name, username and password.
3. On your Open edX instance, the default email settings will have to be configured to use the SMTP backend provided by yourDjango App instead of the default console backend.
4. These setting variables can be set/modified in following file on your Open edX repo/local instance:
Path: edx-platform/lms/envs/common.py
5. The suggested changes to variable settings are as follows:
a. There is a setting for EMAIL_BACKEND
The default setting is:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
This should be changed to:
EMAIL_BACKEND =django.core.mail.backends.smtp.EmailBackend'
b. There is a setting for EMAIL_HOST
The default setting is usually:
EMAIL_HOST = 'smtp.gmail.com'
Change this to the SMTP server setting provided by your email provider eg
EMAIL_HOST = 'smtp.sendgrid.net'
c. There is a setting for EMAIL_PORT
The default setting is usually
EMAIL_PORT = 587
Change appropriate port recommended by your SMTP provider
d. There is a setting for EMAIL_USE_TLS
The default is usually:
EMAIL_USE_TLS = True
Keep the value as
EMAIL_USE_TLS = True
e. Set the EMAIL_HOST_USER setting to the username from your mail service.
Eg if the email/login of your mail service is [email protected], set this value for your EMAIL_HOST_USER
EMAIL_HOST_USER = '[email protected]’
f. Set the EMAIL_HOST_PASSWORD setting to the SMTP password set on your SMTP service
EMAIL_HOST_PASSWORD = 'setpasswordhere'
g. For the DEFAULT_FROM_EMAIL, set your SMTP email or chosen from email here
eg
DEFAULT_FROM_EMAIL = ‘[email protected]'
6. Note that you will need to change EMAIL_BACKEND in a couple other places ie
edx-platform/lms/envs/content.py and edx-platform/lms/envs/devstack.py (For your dev environment)
7. An alternate approach is to set/modify the variables in json setting files ie lms.env.json and cms.env.json.
The respective paths on your deployed instance are /edx/app/edxapp/lms.env.json and /edx/app/edxapp/cms.env.json
The json settings variables will override the settings sets in common.py.
8. After setting the variables restart edxapp and edxapp worker services.
sudo /edx/bin/supervisorctl restart edxapp:
sudo /edx/bin/supervisorctl restart edxapp_worker:
That should do it, you users should now receive email much more reliably!
Here is an example of settings, when Sendgrid is the chosen email provider:
Python common variable file settings:
edx-platform/lms/envs/common.py:
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = "smtp.sendgrid.net"
EMAIL_PORT = 587
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = "[email protected]"
EMAIL_HOST_PASSWORD = "setpasswordhere"
EMAIL_HOST_USER = "setusernamehere"
JSON file settings:
lms.env.json and cms.env.json:
"EMAIL_BACKEND": "django.core.mail.backends.smtp.EmailBackend",
"EMAIL_HOST": "smtp.sendgrid.net",
"EMAIL_PORT": 587,
"EMAIL_USE_TLS": true,
"DEFAULT_FROM_EMAIL": "[email protected]",
lms.auth.json and cms.auth.json:
"EMAIL_HOST_PASSWORD": "setpasswordhere",
"EMAIL_HOST_USER": "setusernamehere"
For this reason, it's advisable to sign up for a reliable email service like Sendgrid or Mandrill, and to configure your email to work with this service. This has the added benefit of being able to see email analytics and use a variety of features that come with these services.
Here are steps to set this up with your own Open edX instance:
1. Create an account on a services like Sendgrid or Mandrill
2. Obtain the SMTP server details ie server name, username and password.
3. On your Open edX instance, the default email settings will have to be configured to use the SMTP backend provided by yourDjango App instead of the default console backend.
4. These setting variables can be set/modified in following file on your Open edX repo/local instance:
Path: edx-platform/lms/envs/common.py
5. The suggested changes to variable settings are as follows:
a. There is a setting for EMAIL_BACKEND
The default setting is:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
This should be changed to:
EMAIL_BACKEND =django.core.mail.backends.smtp.EmailBackend'
b. There is a setting for EMAIL_HOST
The default setting is usually:
EMAIL_HOST = 'smtp.gmail.com'
Change this to the SMTP server setting provided by your email provider eg
EMAIL_HOST = 'smtp.sendgrid.net'
c. There is a setting for EMAIL_PORT
The default setting is usually
EMAIL_PORT = 587
Change appropriate port recommended by your SMTP provider
d. There is a setting for EMAIL_USE_TLS
The default is usually:
EMAIL_USE_TLS = True
Keep the value as
EMAIL_USE_TLS = True
e. Set the EMAIL_HOST_USER setting to the username from your mail service.
Eg if the email/login of your mail service is [email protected], set this value for your EMAIL_HOST_USER
EMAIL_HOST_USER = '[email protected]’
f. Set the EMAIL_HOST_PASSWORD setting to the SMTP password set on your SMTP service
EMAIL_HOST_PASSWORD = 'setpasswordhere'
g. For the DEFAULT_FROM_EMAIL, set your SMTP email or chosen from email here
eg
DEFAULT_FROM_EMAIL = ‘[email protected]'
6. Note that you will need to change EMAIL_BACKEND in a couple other places ie
edx-platform/lms/envs/content.py and edx-platform/lms/envs/devstack.py (For your dev environment)
7. An alternate approach is to set/modify the variables in json setting files ie lms.env.json and cms.env.json.
The respective paths on your deployed instance are /edx/app/edxapp/lms.env.json and /edx/app/edxapp/cms.env.json
The json settings variables will override the settings sets in common.py.
8. After setting the variables restart edxapp and edxapp worker services.
sudo /edx/bin/supervisorctl restart edxapp:
sudo /edx/bin/supervisorctl restart edxapp_worker:
That should do it, you users should now receive email much more reliably!
Here is an example of settings, when Sendgrid is the chosen email provider:
Python common variable file settings:
edx-platform/lms/envs/common.py:
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = "smtp.sendgrid.net"
EMAIL_PORT = 587
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = "[email protected]"
EMAIL_HOST_PASSWORD = "setpasswordhere"
EMAIL_HOST_USER = "setusernamehere"
JSON file settings:
lms.env.json and cms.env.json:
"EMAIL_BACKEND": "django.core.mail.backends.smtp.EmailBackend",
"EMAIL_HOST": "smtp.sendgrid.net",
"EMAIL_PORT": 587,
"EMAIL_USE_TLS": true,
"DEFAULT_FROM_EMAIL": "[email protected]",
lms.auth.json and cms.auth.json:
"EMAIL_HOST_PASSWORD": "setpasswordhere",
"EMAIL_HOST_USER": "setusernamehere"