Setup SMTP Email on Open edX

With Open edX Ginkgo, integrating an SMTP email account like Google’s Gmail is as simple as setting a few parameter values in the four JSON configuration files for the LMS and Course Management Studio, each of which are located in /edx/app/edxapp/. Get SMTP email working on your Open edX instance in less than an hour with this step-by-step how-to guide.

Summary

The native build of Open edX relies on a simple email generator utility that comes with Ubuntu 16.04. While this technically works, the messages that it generates for new user activations, password reset instructions, and welcome messages are generally universally flagged as spam by common email management client applications like MS Outlook, Mac Mail and so on. Fortunately however, the architects of Open edX have made it easy for you to integrate an SMTP email account to your instance. Take note that the configuration procedure has been simplified over time, but much of the online documentation that I find has not kept pace with these changes, and this can make it appear as though getting SMTP email working is more complicated that it really is.

We’ll integrate a Google Gmail account in this tutorial, but you can use just about any other SMTP mail provider and these instructions will still be valid. Google’s Gmail email service is designed to be accessed by third party applications. The email management software that you use on your Desktop and mobile devices for example are third-party apps that provide the means to quickly connect and synchronize your local email message storage system to Gmail’s email services.

SMTP is a standardized protocol that Gmail and many other email providers use to allow third party applications to integrate and synchronize with the central email servers of the service provider. Apple and Android both provide really good out-of-the-box mobile apps for email that let you connect to a Gmail account; usually requiring no more than a user name and password. Open edX uses the same approach, but without the nice GUI interface.

Setup Procedure

1. Configure Your Gmail Account

There is one small but important change that you’ll need to make to your default Gmail account settings in order for Gmail to allow Open edX to connect. After logging in to your Gmail account from a web browser, navigate to https://myaccount.google.com/lesssecureapps to change the setting for “Allow less secure apps” to “On”.

2. Edit /edx/app/edxapp/lms.auth.json

lms.auth.json contains authorization credentials for the various subsystems that support the Learning Management System (LMS) application; email username and password being two such credentials. Each time the LMS attempts to send an email message it refers to the username and password from this file to establish a connection and send the message using the Gmail SMTP email service.

Pro Tip: Keep a backup copy of the original versions of each of the four JSON files in /edx/app/edxapp. JSON syntax is as rigid as it is unforgiving, and any syntax errors in these four JSON files will prevent your Open edX platform from restarting.

3. Edit /edx/app/edxapp/cms.auth.json

cms.auth.json contains authorization credentials for the various subsystems that support the Course Management Studio (CMS) application. The structure of this file is similar, but not identical to that of lms.auth.json from the previous step. You’ll also add your Gmail username and password to this file.

4. Edit /edx/app/edxapp/lms.env.json

lms.env.json contains application parameters and option values for the LMS. You’ll do two things in this file. First, you’ll add your Google Gmail SMTP settings, and second, you’ll set your gmail email address in various locations in the file.

Note that you’ll find other parameters in this file with an “EMAIL_” prefix. If I don’t mention them in this article then they’re not required for setting up SMTP email.

EMAIL_BACKENDThe default value might look similar, so check this carefully to ensure that you’re instructing Django to use SMTP rather than the default Ubuntu email generator utility.
EMAIL_HOSTThis is the fully qualified domain name for the email service that you’re using (Google Gmail in the case of this tutorial). If you’re using a different mail provider then you should ensure that you provide a Fully Qualified Domain Name (FQDM) here.
EMAIL_PORTThe port assignment is specific to the service provider that you’re using, and it’s arbitrary, so don’t try to guess.
EMAIL_USE_TLSThis value is specific to your provider. This is a true/false flag indicating whether email connections will be established using secure HTTPS protocol with TLS (a new improved alternative to SSL).

Note: If you’re using Ginkgo then you can disregard this step. Next you will potentially update several email addresses, depending on the version you are running. Until Ginkgo, the Open edX platform recognized nearly a dozen different email addresses for roles ranging from new user activation to bug reports. If you’re using a version other than Ginkgo then you’ll need to do a search-replace on “@example.com” to correctly set these values.

5. Edit /edx/app/edxapp/cms.env.json

This file is virtually identical in both layout and substance to lms.env.json. You should duplicate all edits that you made in the previous step.

6. Restart Open edX

You’ll need to restart the Open edX platform in order for these changes to take effect. Keep in mind that restarting the platform takes around 10 minutes and that it will be unavailable to learners and instructors during this time. Also keep in mind that any syntax errors you might have made while editing the JSON files will prevent the Open edX platform from starting.


# For Ginkgo and newer
/edx/bin/supervisorctl restart lms
/edx/bin/supervisorctl restart cms
/edx/bin/supervisorctl restart edxapp_worker:

For older versions of Open edX (prior to Ginkgo) you should use this alternative syntax. Note that The “:” character is part of each of these two commands.


/edx/bin/supervisorctl restart edxapp:
/edx/bin/supervisorctl restart edxapp_worker:

7. Test Your Work

You can easily verify your results by requesting a password reset email using the “Forgot Password?” from your Open edX login screen. This simple utility will attempt to use your new SMTP email settings to generate the password reset email using Google Gmail. If it works then you’ll not only instantly receive the email but you’ll also be able to see a copy of the message in the “Sent Mail” for your Gmail account.

8. Troubleshooting

There are a limited set of things that can go wrong, but also a limited set of ways to check your results and so troubleshooting is pretty straightforward. Your two best diagnostic tools are the Javascript console in Google Chrome and the “Sent Mail” folder of your Google Gmail account.

If the password reset screen freezes or reports an error then Check the Javascript console for errors. If you find an HTTP 500 error then this means that Open edX was unsuccessful in its attempt to connect to Gmail. You might be able to find more information in the Javascript object tree explorer.

I hope you found this helpful. Please help me improve this article by leaving a comment below. Thank you!

By |2018-06-29T06:23:02+00:00June 28th, 2018|Categories: Open edX|5 Comments

About the Author:

Lawrence is a full stack developer specializing in web and mobile development using AngularJS, Ionic, Wordpress and Amazon Web Services. He has worked as a freelance technology consultant since 1999. He earned a BS in computer science and mathematics with minors in physics and English from University of North Texas.

5 Comments

  1. Alan August 11, 2018 at 10:35 pm - Reply

    Hello,

    I use devstack for Hawthorn version.
    I follow this tutorial carefully, but not succeeded at setting smtp.

    Could you please help me?

    • admin August 12, 2018 at 6:21 am - Reply

      Hi alan, there weren’t any differences in Ginkgo devstack/fullstack that would affect SMTP setup. Hawthorn is still too new for me to be able to comment. I’d suggest you post a question on Slack just in case you might have run across a bug: https://openedx.slack.com

  2. Phaneendra July 31, 2018 at 12:03 am - Reply

    Hello Lawrence,

    I followed your blog regarding the smtp setup . I got an error saying like There has been 500 error like that.

    • admin July 31, 2018 at 5:22 am - Reply

      reboot the server, note the time, then check the log for the LMS, located here: /edx/var/log/lms/edx.log. you should see some errors generated during the boot process that will provide insights on your problem lies. keep in mind that the time stamps in the log are GMT-0.

  3. MarlonOrozco June 29, 2018 at 9:56 am - Reply

    Excellent

Leave A Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.