title: SMTPServerDisconnected: please run connect() first
body: <p>I'm exploring flask and attempting to setup a simple web app with secure registration and sign in. I'm using flask-security to do this. Unfortunately, when I navigate to the send confirmation page I'm getting the error: "smtpserverdisconnected: please run connect() first".</p>
  
  <p>Below are the relevant files I've written. <code>run.py</code> drives the entire application.</p>
  
  <p>run.py (this is next to the <code>app</code> folder)</p>
  
  <pre><code>#!venv/bin/python
  from app import app
  app.run(debug = True)
  </code></pre>
  
  <p>Everything below here is in the <code>app</code> folder</p>
  
  <p><strong>__init__</strong>.py</p>
  
  <pre><code>from flask import Flask
  from flask.ext.mail import Mail
  from flask.ext.sqlalchemy import SQLAlchemy
  
  app = Flask(__name__)
  app.config.from_object('config')
  
  db = SQLAlchemy(app)
  mail = Mail(app)
  
  import models
  import views
  
  @app.before_first_request
  def create_user():
      db.create_all()
      models.user_datastore.create_user(email = 'user@example.com',
              password = 'password')
      db.session.commit()
  
  if __name__ == '__main__':
      app.run()
  </code></pre>
  
  <p>models.py</p>
  
  <pre><code>from app import db, app
  from flask.ext.sqlalchemy import SQLAlchemy
  from flask.ext.security import SQLAlchemyUserDatastore,\
          UserMixin, RoleMixin, Security
  
  roles_users = db.Table('roles_users',
          db.Column('user_id', db.Integer(), db.ForeignKey('user.id')),
          db.Column('role_id', db.Integer(), db.ForeignKey('role.id')))
  
  class Role(db.Model, RoleMixin):
      id = db.Column(db.Integer(), primary_key = True)
      name = db.Column(db.String(80), unique = True)
      description = db.Column(db.String(255))
  
  class User(db.Model, UserMixin):
      id = db.Column(db.Integer, primary_key = True)
      email = db.Column(db.String(255), unique = True)
      password = db.Column(db.String(255))
      active = db.Column(db.Boolean())
      confirmed_at = db.Column(db.DateTime())
      roles = db.relationship('Role', secondary = roles_users,
              backref = db.backref('users', lazy = 'dynamic'))
  
  user_datastore = SQLAlchemyUserDatastore(db, User, Role)
  security = Security(app, user_datastore)
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>from app import app
  from flask import render_template
  from flask.ext.security import login_required
  
  @app.route('/')
  @login_required
  def index():
      return render_template('index.html')
  </code></pre>
  
  <p>edit: also, here is the config file I'm using</p>
  
  <pre><code>DEBUG      = True
  SECRET_KEY = 'secret'
  SQLALCHEMY_DATABASE_URI = 'sqlite://'
  
  SECURITY_PASSWORD_HASH = 'sha512_crypt'
  SECURITY_PASSWORD_SALT = 'salt'
  SECURITY_CONFIRMABLE = True
  SECURITY_REGISTERABLE = True
  SECURITY_RECOVERABLE = True
  SECURITY_TRACKABLE = True
  SECURITY_CHANGEABLE = True
  
  MAIL_SERVER = 'smtp.zoho.com'
  MAIL_PORT = 465
  MAIL_USE_TLS = False
  MAIL_USE_SSL = True
  MAIL_DEBUG = True
  MAIL_USERNAME = 'myaddress@mydomain'
  MAIL_PASSWORD = 'password'
  </code></pre>