diff options
| -rw-r--r-- | famille.py | 11 | ||||
| -rw-r--r-- | settings.ini | 8 |
2 files changed, 18 insertions, 1 deletions
@@ -9,6 +9,7 @@ from docutils import core from docutils.writers.html4css1 import Writer from datetime import datetime from bs4 import BeautifulSoup +from flask_mail import Mail, Message def rstify(string): w = Writer() @@ -18,6 +19,7 @@ def rstify(string): # configuration app = Flask(__name__) app.config.from_envvar('CONF') +mail = Mail(app) @app.template_filter('shortify') def shortify(string): @@ -90,6 +92,15 @@ def add_news(): if request.method == 'POST': content = request.form['content'] content_cache = rstify(content) + + # send email + emails = query_db("SELECT email from users where notify=1") + emails = [email["email"] for email in emails] + message = Message(request.form['title'], sender="news.horel@gmail.com") + message.html = content_cache + message.recipients = emails + mail.send(message) + cur = g.db.execute("INSERT INTO news " "('title', 'content', 'user_id', 'content_cache') " "VALUES (?, ?, ?, ?)", diff --git a/settings.ini b/settings.ini index 928c6f4..f1e9892 100644 --- a/settings.ini +++ b/settings.ini @@ -2,4 +2,10 @@ DATABASE = 'famille.db' DEBUG = True SECRET_KEY = '\x95\x98j\xcaL\xaeA\xf9\xe6-\xa7uV\xe5Y\x83\xe0\xab\x00\xb6\xeb\xde\xc2\x14' USERNAME = 'admin' -PASSWORD = 'default'
\ No newline at end of file +PASSWORD = 'default' + +MAIL_SERVER = 'smtp.gmail.com' +MAIL_USE_TLS = True +MAIL_PORT = 587 +MAIL_USERNAME = 'news.horel@gmail.com' +MAIL_PASSWORD = 'Dlmatc06' |
