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", "*****@*****.**"), recipients=[email] ) conn.send(message) flash("You have created a new forum. Team members have been notified.", "info") return redirect(url_for("posts"))
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", "*****@*****.**"), recipients=[email], subject=subject) msg.body = message msg.html = message_html conn.send(msg) return "Mails sent!"
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", "*****@*****.**"), recipients=[email] ) conn.send(message) flash("You've posted a comment. Paricipants will be notified", "info") return redirect(url_for("singlepost_get", id=id))
app.logger.info(charge) 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'])
def mail_bulk_connection(): mail = Mail(app) return mail.connect()
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__':