aboutsummaryrefslogtreecommitdiffstats
path: root/famille.py
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@gmail.com>2017-07-23 15:18:41 -0400
committerGuillaume Horel <guillaume.horel@gmail.com>2017-07-23 15:36:29 -0400
commit26b653dbb9fda6f70ae1caac812c151c5f706bb1 (patch)
treeb2d3617a22b57e9be4119593dc537c0249c33c9c /famille.py
parent6c9c39b6856f8c7540944413bcdc47d02affa237 (diff)
downloadfamille-flask-26b653dbb9fda6f70ae1caac812c151c5f706bb1.tar.gz
handle comments through email responsesemail
Diffstat (limited to 'famille.py')
-rw-r--r--famille.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/famille.py b/famille.py
index bc44f4c..9d9894d 100644
--- a/famille.py
+++ b/famille.py
@@ -11,10 +11,9 @@ from datetime import datetime
import time
from email import utils
from bs4 import BeautifulSoup
-from flask_mail import Mail, Message
import locale
from smartypants import smartypants, Attr
-
+from email_helpers import GmailEmailMessage
locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8')
@@ -27,7 +26,6 @@ def rstify(string):
# configuration
app = Flask(__name__)
app.config.from_envvar('CONF')
-mail = Mail(app)
@app.template_filter('shortify')
def shortify(string):
@@ -97,7 +95,6 @@ def get_db():
g.timezone = pytz.common_timezones
return db
-
@app.teardown_appcontext
def close_db(error):
"""Closes the database again at the end of the request."""
@@ -152,15 +149,18 @@ def add_news():
emails = query_db("SELECT email from users where notify=1")
emails = [email["email"] for email in emails if email["email"]]
if emails:
- message = Message(request.form['title'],
- sender="news.horel@gmail.com")
- message.html = content_cache
+ message = GmailEmailMessage()
+ message['to'] = emails
+ message['subject'] = request.form['title']
+ message['reply-to'] = "news.horel+{}@gmail.com".format(news_id)
+ message.set_content(content)
url = url_for('show_news', news_id=news_id, _external=True)
- message.html += ("<p style='margin-top:2em'>Vous pouvez "
- "<a href='{0}'>Lire cette nouvelle</a> "
- "sur le site de la famille.</p>").format(url)
- message.recipients = emails
- mail.send(message)
+ html_content = content_cache +
+ ("<p style='margin-top:2em'>Vous pouvez "
+ "<a href='{0}'>Lire cette nouvelle</a> "
+ "sur le site de la famille.</p>").format(url)
+ message.add_alternative(html_content, subtype='html')
+ message.send()
return redirect(url_for('show_news', news_id=news_id))
else: