Lesson 3B

Email with OAuth 2 & Large Application Structure

Share Tweet

Contents

  1. Resources
  2. Introduction
  3. Part 1: Email with OAuth 2.0
  4. Part 2: Large Application Structure
  5. Exercises
  6. Further Reading
  7. Troubleshooting

Resources

  • Appendix A: Send Emails with Gmail Based on OAuth 2.0 Authentication
  • Textbook: "Miguel Grinberg. Flask Web Development, Second Edition. O'Reilly Media, Inc., 2018." Some up-to-date modifications of the following chapters will be also presented on this page.
    • Chapter 6: Email
    • Chapter 7: Large Application Structure
  • Lesson 3B - Sample Code
  • Python IDE:

Introduction

This lesson will cover the topics that are very important to the rest of this course. First, we present how to implement an email handler for your application based on popular services such as Gmail, Microsoft 365 with OAuth 2.0 authentication mechanism. After completing this first topic, you will get familiar with calling APIs from third-party services for authentication and performing specific services. Most applications will grow in complexity over time, thus you need to organize the project structure in the way that you can easily maintain and update your application in the long-term. The second topic of this lesson will present a basic multiple-file Flask application structure. Since this topic is mainly a hands-on practice section, we will organize it as a self-study lesson. The Resources section will provide you with some useful teaching-and-learning materials.


Part 1: Email with OAuth 2.0

In this section, we will show you two step-by-step tutorials that will help you to implement an email handler for your application based on Gmail and Microsoft 365 with OAuth 2.0 authentication mechanism.

  • Sending Emails with Gmail Based on OAuth 2.0 Authentication
  • Microsoft Graph — Send Mail API |

Part 2: Large Application Structure

The demonstration program that we use in the previous lessons is just a single source code file where we store all things into a single file, such as configurations, web form and database definitions, view functions. Although this approach can be convenient for small web applications, it does not scale well for a larger one. Therefore, this section will present a basic multiple-file Flask application structure that you can easily maintain and update your application in the long-term. We organize this section as a self-study lesson based on Chapter 7 in the textbook.


Exercises

The Exercises section was moved to this page.


Further Reading

  1. Flask-WTF — User's Guide
  2. Flask-SQLAlchemy

Troubleshooting

  1. If you get this error message - Exception: Install 'email_validator' for email validation support. - when creating a database migration by executing such as flask db upgrade command, you can try to install email_validator extension by executing the command pip install email-validator in the current working Python environment.

Relaxing 🧘