Example #1
0
#!/bin/env python

# Author Balbir Singh <balbir@aol.in>
# Date 15th September 2015


from flask import Flask
from flask.ext.mail import Mail, Message

app = Flask(__name__)
mail = Mail(app)

app.config["MAIL_SERVER"] = "email-smtp.us-east-1.amazonaws.com"
app.config["MAIL_PORT"] = 587
app.config["MAIL_USE_TLS"] = True
app.config["MAIL_USERNAME"] = "AKIAIWW4MPBTQP3K26VQ"
app.config["MAIL_PASSWORD"] = "AnPrQHdi8lUpmSNJQbfn8IYLpilti82gx73L7yTSkM4f"
app.config["FLASKY_MAIL_SUBJECT_PREFIX"] = "[Flasky]"
app.config["FLASKY_MAIL_SENDER"] = "Flasky Admin <flasky@goeuro.me>"
app.config["FLASKY_ADMIN"] = "balbir97@gmail.com"

msg = Message("test subject", sender="you@goeuro.me", recipients=["balbir97@gmail.com"])
msg.body = "text body"
msg.html = "<b>HTML</b> body"

with app.app_context():
    mail.send(msg)
Example #2
0
basedir = os.path.abspath(os.path.dirname(__file__))

app = Flask(__name__)
app.config["SECRET_KEY"] = "hard to guess string"
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + os.path.join(basedir, "data.sqlite")
app.config["SQLALCHEMY_COMMIT_ON_TEARDOWN"] = True
track_modifications = app.config.setdefault("SQLALCHEMY_TRACK_MODIFICATIONS", True)
app.config["MAIL_SERVER"] = "smtp.qq.com"
app.config["MAIL_PORT"] = 465
app.config["MAIL_USE_TLS"] = False
app.config["MAIL_USE_SSL"] = True
app.config["MAIL_USERNAME"] = "422296631"
app.config["MAIL_PASSWORD"] = "cvyojlghmekacbdg"
app.config["FLASKY_MAIL_SUBJECT_PREFIX"] = "[Flasky]"
app.config["FLASKY_MAIL_SENDER"] = "Flasky Admin <422296631@qq.com>"
app.config["FLASKY_ADMIN"] = "422296631@qq.com"

manager = Manager(app)
db = SQLAlchemy(app)
bootstrap = Bootstrap(app)
moment = Moment(app)
mail = Mail(app)
migrate = Migrate(app, db)
manager.add_command("db", MigrateCommand)


class Role(db.Model):
    __tablename__ = "roles"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64), unique=True)
Example #3
0
basedir = os.path.abspath(os.path.dirname(__file__))


app = Flask(__name__)
app.config["SECRET_KEY"] = "nejak blba sulinovina hovadska"
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + os.path.join(basedir, "data.sqlite")
# print('sqlite:///' + os.path.join(basedir, 'data.sqlite'))
app.config["SQLALCHEMY_COMMIT_ON_TEARDOWN"] = True
app.debug = True
app.config["MAIL_SERVER"] = "smtp.googlemail.com"
app.config["MAIL_PORT"] = 587
app.config["MAIL_USE_TLS"] = True
app.config["MAIL_USERNAME"] = os.environ.get("MAIL_USERNAME")
app.config["MAIL_PASSWORD"] = os.environ.get("MAIL_PASSWORD")
app.config["FLASKY_MAIL_SUBJECT_PREFIX"] = "[Flasky] "
app.config["FLASKY_MAIL_SENDER"] = "Flasky Admin <flasky@example.com>"
app.config["FLASKY_ADMIN"] = os.environ.get("FLASKY_ADMIN")

manager = Manager(app)
bootstrap = Bootstrap(app)
moment = Moment(app)
db = SQLAlchemy(app)
migrate = Migrate(app, db)
mail = Mail(app)


def make_shell_context():
    return dict(app=app, db=db, User=User, Role=Role)


manager.add_command("shell", Shell(make_context=make_shell_context))
Example #4
0
from threading import Thread
import os

basedir = os.path.abspath(os.path.dirname(__file__))

app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + os.path.join(basedir, "data.sqlite")
app.config["SQLALCHEMY_COMMIT_ON_TEARDOWN"] = True
app.config["SECRET_KEY"] = "hard to guess string"
app.config["MAIL_SERVER"] = "smtp.googlemail.com"
app.config["MAIL_PORT"] = 587
app.config["MAIL_USE_TLS"] = True
app.config["MAIL_USERNAME"] = os.environ.get("MAIL_USERNAME")
app.config["MAIL_PASSWORD"] = os.environ.get("MAIL_PASSWORD")
app.config["FLASKY_MAIL_SUBJECT_PREFIX"] = "[Flasky]"
app.config["FLASKY_MAIL_SENDER"] = "Flasky Admin <woody89104@gmail.com>"
app.config["FLASKY_ADMIN"] = os.environ.get("FALSKY_ADMIN")
manager = Manager(app)
bootstrap = Bootstrap(app)
moment = Moment(app)
db = SQLAlchemy(app)
migrate = Migrate(app, db)
manager.add_command("db", MigrateCommand)
mail = Mail(app)


@app.route("/", methods=["GET", "POST"])
def index():
    form = NameForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.name.data).first()
Example #5
0
basedir = os.path.abspath(os.path.dirname(__file__))

app = Flask(__name__)
app.config["SECRET_KEY"] = "hard to guess string"
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + os.path.join(basedir, "data.db")
app.config["SQLALCHEMY_COMMIT_ON_TEARDOWN"] = True

# mail configuration
app.config["MAIL_SERVER"] = "smtp.163.com"
app.config["MAIL_PORT"] = 465
app.config["MAIL_USE_SSL"] = True
app.config["MAIL_USERNAME"] = os.environ.get("MAIL_USERNAME")
app.config["MAIL_PASSWORD"] = os.environ.get("MAIL_PASSWORD")
app.config["FLASKY_MAIL_SUBJECT_PREFIX"] = "[Flasky]"
app.config["FLASKY_MAIL_SENDER"] = "whn <whn20091100@163.com>"
app.config["FLASKY_ADMIN"] = os.environ.get("FLASKY_ADMIN")

db = SQLAlchemy(app)
bootstrap = Bootstrap(app)
moment = Moment(app)
manager = Manager(app)
migrate = Migrate(app, db)
mail = Mail(app)


class Nameform(Form):
    name = StringField("What is you name", validators=[DataRequired()])
    submit = SubmitField("Submit")

Example #6
0
app = Flask(__name__)

app.debug = True
app.config["SECRET_KEY"] = "hard to guess string"
app.config["SQLALCHEMY_DATABASE_URI"] = "mysql://root:123456@10.1.1.7/flask"
app.config["SQLALCHEMY_COMMIT_ON_TEARDOWN"] = True
app.config["MAIL_SERVER"] = "smtp.163.com"
app.config["MAIL_PORT"] = 465
# app.config['MAIL_USE_TLS'] = True
app.config["MAIL_USE_SSL"] = True
app.config["MAIL_USERNAME"] = os.environ.get("MAIL_USERNAME")
app.config["MAIL_PASSWORD"] = os.environ.get("MAIL_PASSWORD")
app.config["FLASKY_MAIL_SUBJECT_PREFIX"] = "[Flasky]"
app.config["FLASKY_ADMIN"] = os.environ.get("FLASKY_ADMIN")
app.config["FLASKY_MAIL_SENDER"] = "Flasky Admin <%s>" % os.environ.get("FLASKY_ADMIN")
app.config["SECURITY_EMAIL_SENDER"] = os.environ.get("FLASKY_ADMIN")
track_modifications = app.config.setdefault("SQLALCHEMY_TRACK_MODIFICATIONS", True)

manager = Manager(app)
bootstrap = Bootstrap(app)
moment = Moment(app)
# mail = Mail(app)
db = SQLAlchemy(app)


class NameForm(Form):
    name = StringField("what is your name?", validators=[Required()])
    submit = SubmitField("Submit")

Example #7
0
# 配置变量的通用密钥,必须要保证其他人不知道你所用的字符串,最后从环境变量中导入

app.config["SQLALCHEMY_DATABASE_URI"] = "mysql://root:examplekey@localhost/User"
app.config["SQLALCHEMY_COMMIT_ON_TEARDOWN"] = True
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True
# 数据库的一些配置,这里用的是mysql

app.config["MAIL_SERVER"] = "smtp.qq.com"
app.config["MAIL_PORT"] = 25
app.config["MAIL_USE_TLS"] = True
# app.config['MAIL_USE_SSL'] = True
app.config["MAIL_USERNAME"] = "example@qq.com"  # os.environ.get('MAIL_USERNAME')
app.config["MAIL_PASSWORD"] = "#################"  # os.environ.get('MAIL_PASSWORD') 最好从环境变量中导入
# app.config['MAIL_DEBUG'] = True
app.config["FLASKY_MAIL_SUBJECT_PREFIX"] = "[Flasky]"
app.config["FLASKY_MAIL_SENDER"] = "example@qq.com"
app.config["FLASKY_ADMIN"] = "example@qq.com"  # os.environ.get('FLASKY_ADMIN')
# 邮箱的一些配置,这里用的是qq邮箱


class NameForm(Form):
    name = StringField("what is your name,bitch?", validators=[Required()])
    submit = SubmitField("Submit")


# 这里定义的是表单


class Role(db.Model):
    __tablename__ = "roles"
    id = db.Column(db.Integer, primary_key=True)
Example #8
0
app = Flask(__name__)
# config mail
app.config["MAIL_SERVER"] = "smtp.126.com"
app.config["MAIL_PORT"] = 25
app.config["MAIL_USE_TLS"] = True
app.config["MAIL_USERNAME"] = os.environ.get("MAIL_USERNAME")
app.config["MAIL_PASSWORD"] = os.environ.get("MAIL_PASSWORD")
app.config["FLASKY_ADMIN"] = os.environ.get("FLASKY_ADMIN")

app.config["SECRET_KEY"] = "you never guess"
app.config["SQLALCHEMY_COMMIT_ON_TEARDOWN"] = True

# mail message
app.config["FLASKY_MAIL_SUBJECT_PREFIX"] = "[Flasky]"
app.config["FLASKY_MAIL_SENDER"] = "harmonica39@126.com"
# send email
def send_async_email(app, msg):
    with app.app_context():
        mail.send(msg)


def send_email(to, subject, template, **kwargs):
    msg = Message(
        app.config["FLASKY_MAIL_SUBJECT_PREFIX"] + subject, sender=app.config["FLASKY_MAIL_SENDER"], recipients=[to]
    )
    msg.body = render_template(template + ".txt", **kwargs)
    msg.html = render_template(template + ".html", **kwargs)
    thr = Thread(target=send_async_email, args=[app, msg])
    thr.start()
    return thr
Example #9
0
if __name__ == "__main__":
    bootstrap = Bootstrap()

    app = Flask(__name__)
    app.config["SECRET_KEY"] = "hard to guess string"
    app.config["SQLALCHEMY_DATABASE_URI"] = "mysql://root:mopon@172.16.34.7:3306/test"
    app.config["SQLALCHEMY_COMMIT_ON_TEARDOWN"] = True

    app.config["MAIL_SERVER"] = "smtp.qiye.163.com"
    app.config["MAIL_PORT"] = 25
    app.config["MAIL_USE_TLS"] = False
    app.config["MAIL_USERNAME"] = "chenxiaolu.sz@mopon.cn"
    app.config["MAIL_PASSWORD"] = "cxl@taijiu2015"
    app.config["FLASKY_MAIL_SUBJECT_PREFIX"] = "[Flasky]"
    app.config["FLASKY_MAIL_SENDER"] = "Flasky Admin <chenxiaolu.sz@mopon.cn>"
    app.config["FLASKY_ADMIN"] = "chenxiaolu.sz@mopon.cn"
    app.config["FLASKY_POSTS_PER_PAGE"] = 2
    app.config["FLASKY_FOLLOWERS_PER_PAGE"] = 2
    app.config["FLASKY_COMMENTS_PER_PAGE"] = 2

    bootstrap.init_app(app)
    moment.init_app(app)
    db.init_app(app)
    login_manager.init_app(app)
    mail.init_app(app)
    pagedown.init_app(app)

    from model import User, AnonymousUser

    @login_manager.user_loader
Example #10
0
from flask import Flask

app = Flask(__name__)
app.secret_key = "ReallySecretKeyUsedForImportantThings"
app.config["FLASKY_MAIL_SUBJECT_PREFIX"] = "[FFRL BackboneAdmin]"
app.config["FLASKY_MAIL_SENDER"] = "admin@ffrl.de"

from app import views
Example #11
0
app = Flask(__name__)
# 数据库的配置
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + os.path.join(basedir, "data.sqlite")
app.config["SQLALCHEMY_COMMIT_ON_TEARDOWN"] = True
db = SQLAlchemy(app)

app.config["SECRET_KEY"] = "hard to guess string"

# 邮件设置
app.config["MaIL_SERVER"] = "smtp.126.com"
app.config["MAIL_PORT"] = 25
app.config["MAIL_USE_TLS"] = True
app.config["MAIL_USERNAME"] = "hugesoft@126.com"
app.config["MAIL_PASSWORD"] = "enter0087!"
app.config["FLASKY_MAIL_SUBJECT_PREFIX"] = "[Flasky]"
app.config["FLASKY_MAIL_SENDER"] = "Flasky Admin <hugesoft@126.com>"
app.config["FLASKY_ADMIN"] = "hugesoft@126.com"

app.debug = True
manager = Manager(app)
bootstrap = Bootstrap(app)
moment = Moment(app)
mail = Mail(app)


def send_async_email(app, msg):
    with app.app_context():
        mail.send(msg)


# 邮件发送函数
login_manager.session_protection = "strong"
login_manager.login_view = "login"

app = Flask(__name__)
app.config.from_object("config")

from app.model import db

db.init_app(app)

login_manager.init_app(app)

from flask.ext.mail import Mail, Message

app.config["FLASKY_MAIL_SUBJECT_PREFIX"] = "[Flasky]"
app.config["FLASKY_MAIL_SENDER"] = "Flasky Admin <traktoro_13@mail.ru>"
mail = Mail(app)

from flask.ext.moment import Moment

moment = Moment(app)

from model import Permission


@app.context_processor
def inject_permissions():
    return dict(Permission=Permission)


def send_async_email(app, msg):
Example #13
0
app = Flask(__name__)
manager = Manager(app)
bootstrap = Bootstrap(app)
moment = Moment(app)

app.config["SECRET_KEY"] = appconfig.config["SECRET_KEY"]
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + os.path.join(basedir, "data.sqlite")
app.config["SQLALCHEMY_COMMIT_ON_TEARDOWN"] = True
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True

mail = Mail(app)
app.config["MAIL_SERVER"] = "localhost"
app.config["MAIL_PORT"] = "25"
app.config["MAIL_USERNAME"] = "flasky"
app.config["FLASKY_MAIL_SUBJECT_PREFIX"] = "[Flasky]"
app.config["FLASKY_MAIL_SENDER"] = "Flasky Admin <flasky@localhost.localdomain>"
app.config["FLASKY_ADMIN"] = os.environ.get("FLASKY_ADMIN")

db = SQLAlchemy(app)

migrate = Migrate(app, db)
manager.add_command("db", MigrateCommand)


class Role(db.Model):
    __tablename__ = "roles"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64), unique=True)
    users = db.relationship("User", backref="role")

    def __repr__(self):
Example #14
0
basedir = os.path.dirname(__file__)
app = Flask(__name__)
# sql
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + os.path.join(basedir, "data-sqlite")
app.config["SQLALCHEMY_COMMIT_ON_TRARDOWN"] = True
app.config["SECRET_KEY"] = "hard to guess string"
# email
app.config["MAIL_SERVER"] = "smtp.163.com"
app.config["MAIL_PORT"] = 25
# app.config['MAIL_USE_TLS'] = True
app.config["MAIL_USERNAME"] = os.environ.get("MAIL_USERNAME")
app.config["MAIL_PASSWORD"] = os.environ.get("MAIL_PASSWORD")
app.config["FLASKY_ADMIN"] = os.environ.get("FLASKY_ADMIN")
app.config["FLASKY_MAIL_SUBJECT_PREFIX"] = "[Flasky]"
app.config["FLASKY_MAIL_SENDER"] = "Flasky Admin <zhangyuhan3030@163.com>"

mail = Mail(app)

manager = Manager(app)
bootstrap = Bootstrap(app)
moment = Moment(app)
db = SQLAlchemy(app)
migrate = Migrate(app, db)
manager.add_command("db", MigrateCommand)


def send_async_email(app, msg):
    with app.app_context():
        mail.send(msg)
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + os.path.join(basedir, "data.sqlite")
app.config["SQLALCHEMY_COMMIT_ON_TEARDOWN"] = True
app.config["DEBUG"] = True
app.config["SECRET_KEY"] = "hey hey, you socks"  # 提供给flask-wtf模块实现scr攻击保护
Bootstrap(app)  # 使用flask_bootstrap扩展
Moment(app)
db = SQLAlchemy(app)
manager = Manager(app)

app.config["MAIL_SERVER"] = "smtp.163.com"
app.config["MAIL_PORT"] = 25
app.config["MAIL_USE_TLS"] = False
app.config["MAIL_USERNAME"] = input("请输入邮箱地址:")
app.config["MAIL_PASSWORD"] = getpass.getpass("请输入邮箱密码:")
app.config["FLASKY_MAIL_SUBJECT_PREFIX"] = "[Flasky]"
app.config["FLASKY_MAIL_SENDER"] = "weiman_gz@163.com"
mail = Mail(app)


def send_async_email(app, msg):  # 用到app的config数据,需要使用app的上下文
    with app.app_context():
        mail.send(msg)


def send_mail(send_to, subject, template, **kw):  # 使用线程执行邮件发送,避免请求阻塞
    msg = Message(
        app.config["FLASKY_MAIL_SUBJECT_PREFIX"] + subject, sender=app.config["MAIL_USERNAME"], recipients=[send_to]
    )
    msg.body = render_template(template + ".txt", **kw)
    msg.html = render_template(template + ".html", **kw)
    thr = Thread(target=send_async_email, args=[app, msg])
Example #16
0
basedir = os.path.abspath(os.path.dirname(__file__))

# from flask.ext.script import Manager
app = Flask(__name__)
bootstrap = Bootstrap(app)
moment = Moment(app)
app.config["SECRET_KEY"] = "s3cr3t"
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + os.path.join(basedir, "data.sqlite")
app.config["SQLALCHEMY_COMMIT_ON_TEARDOWN"] = True
app.config["MAIL_SERVER"] = "smtp.googlemail.com"
app.config["MAIL_USE_TLS"] = True
app.config["MAIL_USERNAME"] = os.environ.get("MAIL_USERNAME")
app.config["MAIL_PASSWORD"] = os.environ.get("MAIL_PASSWORD")
app.config["FLASKY_MAIL_SUBJECT_PREFIX"] = "[Flasky]"
app.config["FLASKY_MAIL_SENDER"] = "1294462476@qq.com"
app.config["FLASKY_ADMIN"] = os.environ.get("FLASKY_ADMIN")

db = SQLAlchemy(app)
manager = Manager(app)

migrate = Migrate(app, db)
manager.add_command("db", MigrateCommand)
mail = Mail(app)


def send_email(to, subject, template, **kwargs):
    msg = Message(
        app.config["FLASKY_MAIL_SUBJECT_PREFIX"] + subject, sender=app.config["FLASKY_MAIL_SENDER"], recipients=[to]
    )
    msg.body = render_template(template + ".txt", **kwargs)
Example #17
0
manager = Manager(app)

app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + os.path.join(basedir, "data.sqlite")
app.config["SQLALCHEMY_COMMIT_ON_TEARDOWN"] = True
db = SQLAlchemy(app)
bootstrap = Bootstrap(app)

app.config["MAIL_SERVER"] = "smtp.gmail.com"
app.config["MAIL_PORT"] = 465
app.config["MAIL_USE_TLS"] = False
app.config["MAIL_USE_SSL"] = True
app.config["MAIL_USERNAME"] = "pa.xt.ng@gmail.com"
app.config["MAIL_PASSWORD"] = os.environ.get("MAIL_PASSWORD")

app.config["FLASKY_MAIL_SUBJECT_PREFIX"] = "[ONKLAC]"
app.config["FLASKY_MAIL_SENDER"] = "Onklac <onklac@onklac.com>"

mail = Mail(app)


def send_email(by, to, subject="from Onklac", message=""):
    msg = Message(
        app.config["FLASKY_MAIL_SUBJECT_PREFIX"] + subject, sender=app.config["FLASKY_MAIL_SENDER"], recipients=[to]
    )
    msg.body = message
    mail.send(msg)


@app.route("/")
@app.route("/index.html")
def index():
Example #18
0
from flask.ext.migrate import Migrate, MigrateCommand
from flask.ext.mail import Mail, Message

basedir = os.path.abspath(os.path.dirname(__file__))

app = Flask(__name__)
app.config["SECRET_KEY"] = "hard to guess string"
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + os.path.join(basedir, "data.sqlite")
app.config["SQLALCHEMY_COMMIT_ON_TEARDOWN"] = True
app.config["MAIL_SERVER"] = "smtp.qq.com"
app.config["MAIL_PORT"] = 587
app.config["MAIL_USE_TLS"] = True
app.config["MAIL_USERNAME"] = os.environ.get("MAIL_USERNAME")
app.config["MAIL_PASSWORD"] = os.environ.get("MAIL_PASSWORD")
app.config["FLASKY_MAIL_SUBJECT_PREFIX"] = "[Flasky]"
app.config["FLASKY_MAIL_SENDER"] = "Flasky Admin <409951847@qq.com>"
app.config["FLASKY_ADMIN"] = os.environ.get("FLASKY_ADMIN")

manager = Manager(app)
bootstrap = Bootstrap(app)
moment = Moment(app)
db = SQLAlchemy(app)
migrate = Migrate(app, db)
mail = Mail(app)


class Role(db.Model):
    __tablename__ = "roles"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64), unique=True)
    users = db.relationship("User", backref="role", lazy="dynamic")
Example #19
0
from wtforms.validators import Required
from flask import render_template
from flask_bootstrap import Bootstrap
from flask_moment import Moment
from flask import session
from flask import url_for
from threading import Thread

basedir = os.path.abspath(os.path.dirname(__file__))
app = Flask(__name__)
app.config["MAIL_SERVER"] = "smtp.googlemail.com"
app.config["MAIL_PORT"] = 587
app.config["MAIL_USE_TLS"] = True
app.config["MAIL_USERNAME"] = os.environ.get("MAIL_USERNAME")
app.config["MAIL_PASSWORD"] = os.environ.get("MAIL_PASSWORD")
app.config["FLASKY_MAIL_SENDER"] = "Alex Bondar <abondar1992@gmail.com>"
app.config["FLASKY_ADMIN"] = os.environ.get("FLASKY_ADMIN")
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + os.path.join(basedir, "data.sqlite")
app.config["SQLALCHEMY_COMMIT_ON_TEARDOWN"] = True
app.config["SECRET_KEY"] = "fffe16hff"

db = SQLAlchemy(app)


class NameForm(Form):
    name = StringField("What is your name?", validators=[Required()])
    submit = SubmitField("Submit")


##modelsfor db
class Role(db.Model):
Example #20
0
import os

# import ipdb
from flask.ext.mail import Mail
from flask.ext.mail import Message
from flask import Flask, render_template

app = Flask(__name__)

app.config["MAIL_SERVER"] = "smtp.qq.com"
app.config["MAIL_PORT"] = 587
app.config["MAIL_USE_TLS"] = True
app.config["MAIL_USERNAME"] = os.environ.get("MAIL_USERNAME")
app.config["MAIL_PASSWORD"] = os.environ.get("MAIL_PASSWORD")
app.config["FLASK_MAIL_SUBJECT_PREFIX"] = "Lilium Accounts"
app.config["FLASKY_MAIL_SENDER"] = "1372488211@qq.com"

mail = Mail(app)


# todo, 发送邮件找回密码
# def send_email(to, subject, template, **kwargs):
def send_email(to_email, body):
    msg = Message(
        app.config["FLASK_MAIL_SUBJECT_PREFIX"], sender=app.config["FLASKY_MAIL_SENDER"], recipients=[to_email]
    )
    # msg.body=render_template(template+'.txt',**kwargs)
    # msg.html=render_template(template+'.html',**kwargs)
    msg.body = "text body"
    msg.html = "<br><h3>your password for Lilium is <b>  <u>" + str(body) + "</u> </b></h3>"
    with app.app_context():
Example #21
0
File: app.py Project: KennF/Circus
from flask.ext.mail import Mail, Message

app = Flask(__name__)

manager = Manager(app)


app.config["MAIL_SERVER"] = "smtp.gmail.com"
app.config["MAIL_PORT"] = 465
# app.config['MAIL_USE_TLS'] = True
app.config["MAIL_USE_SSL"] = True
app.config["MAIL_USERNAME"] = os.environ.get("MAIL_USERNAME")
app.config["MAIL_PASSWORD"] = os.environ.get("MAIL_PASSWORD")

app.config["FLASKY_MAIL_SUBJECT_PREFIX"] = "[Flasky]"
app.config["FLASKY_MAIL_SENDER"] = "Flasky Admin <cactus.fxy@gmail.com>"

#!!!! It's VERY IMPORTANT - to init mail after setting app.config !!!
mail = Mail(app)


def send_async_email(app, msg):
    with app.app_context():
        mail.send(msg)


def send_email(to, subject, template, **kwargs):
    msg = Message(
        app.config["FLASKY_MAIL_SUBJECT_PREFIX"] + subject, sender=app.config["FLASKY_MAIL_SENDER"], recipients=[to]
    )
    msg.body = render_template(template + ".txt", **kwargs)
Example #22
0
app = Flask(__name__)
manager = Manager(app)
moment = Moment(app)
mail = Mail(app)
bootstrap = Bootstrap(app)

# app configuration
app.config["SECRET_KEY"] = "hard to guess string"
app.config["SQLALCHEMY_DATABASE_URI"] = "mysql://root:LoveDesign**@localhost/flask_dev"
app.config["SQLALCHEMY_COMMIT_ON_TEARDOWN"] = True
app.config["MAIL_SERVER"] = "smtp.qq.com"
app.config["FLASK_ADMIN"] = os.environ.get("FLASK_ADMIN")
app.config["MAIL_PORT"] = 587
app.config["MAIL_USE_TLS"] = True
app.config["FLASKY_MAIL_SUBJECT_PREFIX"] = "[Flasky]"
app.config["FLASKY_MAIL_SENDER"] = "Flasky Admin <18568595@qq.com>"
app.config["MAIL_USERNAME"] = os.environ.get("MAIL_USERNAME")
app.config["MAIL_PASSWORD"] = os.environ.get("MAIL_PASSWORD")
db = SQLAlchemy(app)
migrate = Migrate(app, db)
manager.add_command("db", MigrateCommand)


def send_async_email(app, msg):
    with app.app_context():
        mail.send(msg)


def send_mail(to, subject, template, **kwargs):
    msg = Message(
        app.config["FLASKY_MAIL_SUBJECT_PREFIX"] + subject, sender=app.config["FLASKY_MAIL_SENDER"], recipients=[to]
Example #23
0
from flask.ext.mail import Message

import os

basedir = os.path.abspath(os.path.dirname(__file__))


app = Flask(__name__)  # 创建一个Flask对象
app.config["SECRET_KEY"] = "yangchao_wtf_key"  # wtf防止跨站请求伪造攻击 flask-wtf
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + os.path.join(basedir, "data.sqlite")
app.config["SQLALCHEMY_COMMIT_ON_TEARDOWN"] = True


# 邮件服务测试
app.config["FLASKY_MAIL_SUBJECT_PREFIX"] = "[Flasky]"
app.config["FLASKY_MAIL_SENDER"] = "55617@163.com"
app.config["FLASK_ADMIN"] = os.environ.get("FLASKY_ADMIN")

app.config["MAIL_SERVER"] = "smtp.163.com"
app.config["MAIL_PORT"] = 25
app.config["MAIL_USE_TLS"] = True
app.config["MAIL_USERNAME"] = os.environ.get("MAIL_USERNAME")
app.config["MAIL_PASSWORD"] = os.environ.get("MAIL_PASSWORD")


manager = Manager(app)
bootstrap = Bootstrap(app)
moment = Moment(app)
db = SQLAlchemy(app)
mail = Mail(app)
# 创建数据库迁移
Example #24
0
from flask.ext.wtf import Form
from wtforms import StringField, SubmitField
from wtforms.validators import Required, data_required

from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.migrate import Migrate, MigrateCommand
from flask.ext.mail import Mail

basedir = os.path.abspath(os.path.dirname(__file__))
app = Flask(__name__)
app.config["SECRET_KEY"] = "aaaa"
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + os.path.join(basedir, "data.sqlite")
app.config["SQLALCHEMY_COMMIT_ON_TEARDOWN"] = True

app.config["FLASKY_MAIL_SUBJECT_PREFIX"] = "[Flasky]"
app.config["FLASKY_MAIL_SENDER"] = "<moustachedtom@gmail.com>"

app.config["MAIL_SERVER"] = "smtp.googlemail.com"
app.config["MAIL_PORT"] = 587
app.config["MAIL_USE_TLS"] = True
app.config["MAIL_USER_NAME"] = os.environ.get("MAIL_USERNAME")
app.config["MAIL_PASSWORD"] = os.environ.get("MAIL_PASSWORD")


db = SQLAlchemy(app)
manager = Manager(app)
bootstrap = Bootstrap(app)
moment = Moment(app)
migrate = Migrate(app, db)
mail = Mail(app)
Example #25
0
from flask.ext.migrate import Migrate, MigrateCommand
from flask.ext.mail import Mail
from flask.ext.mail import Message
from threading import Thread

basedir = os.path.abspath(os.path.dirname(__file__))

app = Flask(__name__)
app.config["SECRET_KEY"] = "hard to guess string"
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + os.path.join(basedir, "data.sqlite")
app.config["SQLALCHEMY_COMMIT_ON_TEARDOWN"] = True
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True


app.config["FLASKY_MAIL_SUBJECT_PREFIX"] = "[Flasky]"
app.config["FLASKY_MAIL_SENDER"] = "Flasky Admin <3xxxxxxxxx@qq.com>"
app.config["MAIL_SERVER"] = "smtp.qq.com"
app.config["MAIL_PORT"] = 465
app.config["MAIL_USE_TLS"] = False
app.config["MAIL_USE_SSL"] = True
app.config["MAIL_USERNAME"] = "3xxxxxxxxxxx@qq.com"
app.config["MAIL_PASSWORD"] = "xxxxxxxxxxxx"
app.config["FLASKY_ADMIN"] = "3xxxxxxx@qq.com"


mail = Mail(app)  # 装载电子邮件
manager = Manager(app)  # 装载Manager
bootstrap = Bootstrap(app)  # 装载Bootstrap
moment = Moment(app)  # 装载时间戳
db = SQLAlchemy(app)  # 装载数据库
migrate = Migrate(app, db)  # 装载数据库迁移