title: ImportError: cannot import name 'app' with Flask
body: <p>I have an issue with the configuration of <code>Flask-Mail</code>. </p>
  
  <p>Here is my directory structure:</p>
  
  <pre><code>▾ app/
    ▾ controllers/
        __init__.py
        mail.py
  ▾ config/
      __init__.py
  ▾ run.py
  </code></pre>
  
  <p>In my run.py i have:</p>
  
  <pre><code>from app import app
  
  if __name__ == '__main__':
      app.run()
  </code></pre>
  
  <p>The config is in <code>config/__init__.py</code></p>
  
  <pre><code>import os
  DEBUG = True
  SECRET_KEY = 'my precious'
  PORT = int(os.environ.get('PORT', 5000))
  MAIL_SERVER = 'ssl0.foo.net'
  MAIL_PORT = 465
  MAIL_USE_SSL = True
  MAIL_USERNAME = 'contact@foo.bar'
  MAIL_PASSWORD = 'EwCa2kd'
  </code></pre>
  
  <p>The config is loaded in the <code>app/__init__.py</code></p>
  
  <pre><code>import logging
  
  from flask import Flask
  from app.controllers import pages
  from flask_mail import Mail
  
  app = Flask(__name__)
  app.config.from_object('config.development')
  
  app.register_blueprint(pages.blueprint)
  
  app.logger.setLevel(logging.NOTSET)
  mail = Mail(app)
  </code></pre>
  
  <p>And I would like to create a mail controller in <code>controllers/mail.py</code> with</p>
  
  <pre><code>from flask_mail import Message
  from .. import app, mail
  
  def send_email(subject, sender, recipients, text_body, html_body):
      msg = Message(subject, sender=sender, recipients=recipients)
      msg.body = text_body
      msg.html = html_body
      mail.send(msg)
  </code></pre>
  
  <p>But i can not use <code>mail</code> in this controller, i tried several combinations but i got some import error like : <code>ImportError: cannot import name 'app'</code></p>