title: Email verification with flask-mail
body: <p>I am looking to add email verification to my web app using flask-mail, and after reading the documentation, it seems that I must create a Mail instance using:</p>
  <pre><code>app = Flask(__name__)
  mail = Mail(app)
  </code></pre>
  <p>and then import the app and mail instances.</p>
  <p>However, my current code creates the Flask and Mail instances inside a function as below:</p>
  <pre><code>from flask import Flask
  from flask_sqlalchemy import SQLAlchemy
  from flask_login import LoginManager 
  
  db = SQLAlchemy()
  
  def create_app():
      app = Flask(__name__)
  
      app.config[&quot;SECRET_KEY&quot;] = &quot;9OLWxND4o83j4K4iuopO&quot;
      app.config[&quot;SQLALCHEMY_DATABASE_URI&quot;] = &quot;sqlite:///db.sqlite&quot;
  
      db.init_app(app)
  
      login_manager = LoginManager()
      login_manager.login_view = &quot;auth.login&quot;
      login_manager.init_app(app)
  
      from .models import User
  
      @login_manager.user_loader
      def load_user(user_id):
          return User.query.get(int(user_id))
  
      from .auth import auth as auth_blueprint
      app.register_blueprint(auth_blueprint)
  
      from .main import main as main_blueprint
      app.register_blueprint(main_blueprint)
  
      return app
  </code></pre>
  <p>The above code is in my <code>__init__.py</code> file.
  I can't import the Mail instance into my other files where I register a user because one hasn't actually been defined, it is only in a function.
  The base code was from this tutorial:  <a href="https://www.digitalocean.com/community/tutorials/how-to-add-authentication-to-your-app-with-flask-login" rel="nofollow noreferrer">https://www.digitalocean.com/community/tutorials/how-to-add-authentication-to-your-app-with-flask-login</a> and now I am adding email verification to it.
  To run the web app, I type  <code>db.create_all(app=create_app())</code>  in a Python REPL, which creates my sqlite database, and is the only time the create_all() function is called. And then I type <code>Flask run</code> in my powershell terminal.</p>