Beispiel #1
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():
Beispiel #2
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)


# 邮件发送函数
Beispiel #3
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)
Beispiel #4
0
from flask.ext.mail import Mail, 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["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>"

manager = Manager(app)
bootstrap = Bootstrap(app)
moment = Moment(app)
db = SQLAlchemy(app)
migrate = Migrate(app, db)
manager.add_command("db", MigrateCommand)
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")