本文整理汇总了Python中flask.ext.mail.Mail.connect方法的典型用法代码示例。如果您正苦于以下问题:Python Mail.connect方法的具体用法?Python Mail.connect怎么用?Python Mail.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask.ext.mail.Mail
的用法示例。
在下文中一共展示了Mail.connect方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_post_post
# 需要导入模块: from flask.ext.mail import Mail [as 别名]
# 或者: from flask.ext.mail.Mail import connect [as 别名]
def add_post_post():
members = session.query(User).all()
post = Post(
title=request.form["title"],
content=mistune.markdown(request.form["content"]),
description = request.form["description"],
author=current_user
)
session.add(post)
session.commit()
all_members = []
for member in members:
all_members.append(member.email)
all_members = [str(i) for i in all_members]
describe = request.form["description"] +".... View full message on TeamForum!"
mail=Mail(app)
with mail.connect() as conn:
for email in all_members:
message = Message(subject="A new forum has been created by "+ current_user.name,
body= describe,
sender=("TeamForum", "[email protected]"),
recipients=[email]
)
conn.send(message)
flash("You have created a new forum. Team members have been notified.", "info")
return redirect(url_for("posts"))
示例2: mail
# 需要导入模块: from flask.ext.mail import Mail [as 别名]
# 或者: from flask.ext.mail.Mail import connect [as 别名]
def mail():
mail = Mail(app)
dishes = reduce(
operator.add,
[d.dishes for d in db.session.query(Meal).all()])
dishes_today = filter(
lambda x: x.meal.date == datetime.date.today(),
dishes)
users = db.session.query(User).all()
recipients_info = {}
for user in users:
if user.preference in dishes_today and user.email is not None:
info = {
"name": user.username,
"dish": user.preference.dish_description,
"date": user.preference.meal.date,
"meal_type": user.preference.meal.mealtime.meal_type,
"servery": user.preference.meal.mealtime.servery.name
}
recipients_info[user.email] = info
with mail.connect() as conn:
for email in recipients_info.keys():
message = (
"Hi, %s! \n Your favorite dish %s is available",
"during %s at %s servery today.") % (
recipients_info[email]["name"],
recipients_info[email]["dish"],
recipients_info[email]["meal_type"],
recipients_info[email]["servery"])
message_html = (
"Hi, %s! <br> <br> Your favorite dish <b>%s</b> is ",
"available during <b>%s</b> at <b>%s</b> servery today.") % (
recipients_info[email]["name"],
recipients_info[email]["dish"],
recipients_info[email]["meal_type"],
recipients_info[email]["servery"])
subject = "Hi %s, your favorite food is available today!" % (
recipients_info[email]["name"])
msg = Message(
sender=("Rice Servery App", "[email protected]"),
recipients=[email],
subject=subject)
msg.body = message
msg.html = message_html
conn.send(msg)
return "Mails sent!"
示例3: singlepost_comment
# 需要导入模块: from flask.ext.mail import Mail [as 别名]
# 或者: from flask.ext.mail.Mail import connect [as 别名]
def singlepost_comment(id):
post = session.query(Post).filter_by(id=id).one()
comments = session.query(Comment).filter_by(post_id=post.id).all()
#mail list of people who commented on a forum, dont include comment author
participants = list(set([str(i.author.email) for i in comments
if i.author.email != current_user.email]))
#if the current user is not the creator of forum, add forum creator to list
if post.author.email != current_user.email:
participants.append(str(post.author.email))
content = request.form["content"][:30] + "....View full message on TeamForum."
comment = Comment(
post=session.query(Post).get(id),
content=mistune.markdown(request.form["content"]),
author=current_user
)
session.add(comment)
session.commit()
if len(participants) != 0:
mail=Mail(app)
with mail.connect() as conn:
for email in list(set(participants)):
message = Message(subject= current_user.name + " made a comment on "
+ post.title, body= content,
sender=("TeamForum", "[email protected]"),
recipients=[email]
)
conn.send(message)
flash("You've posted a comment. Paricipants will be notified", "info")
return redirect(url_for("singlepost_get", id=id))
示例4: Purchase
# 需要导入模块: from flask.ext.mail import Mail [as 别名]
# 或者: from flask.ext.mail.Mail import connect [as 别名]
purchase = Purchase(uuid=str(uuid.uuid4()),
email=email,
product=product)
db.session.add(purchase)
db.session.commit()
mail_template = env.get_template('email.html')
mail_html = mail_template.render(purchase=purchase, product=product)
message = Message(
html=mail_html,
subject=app.config['MAIL_SUBJECT'],
sender=app.config['MAIL_FROM'],
recipients=[email])
with mail.connect() as conn:
conn.send(message)
return render_template('success.html', url=purchase.uuid)
@app.route('/test/<product_id>')
def test(product_id):
"""Return a test page for live testing the "purchase" button."""
test_product = Product.query.get(product_id)
return render_template(
'test.html',
test_product=test_product,
stripe_key=app.config['STRIPE_PUBLIC_KEY'],
site_name=app.config['SITE_NAME'])
if __name__ == '__main__':