+ previousvote = query_db('select id, is_open, id_group from votes where id = ?', [voteid], one=True)
+ if previousvote is None or previousvote['is_open'] == 0:
+ users_to_vote = query_db('select users.email, users.name from users join user_group on users.id=user_group.id_user where user_group.id_group = ?', [previousvote['id_group']])
+ for user in users_to_vote:
+ link = request.url_root + url_for('vote', idvote=voteid)
+ BODY = string.join((
+ "From: %s" % EMAIL,
+ "To: %s" % user['email'],
+ "Subject: [Cavote] A vote has been opened for your group",
+ "Date: %s" % time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()).decode('utf-8'),
+ "X-Mailer: %s" % VERSION,
+ "",
+ "A vote has been opened and you are in a group concerned by it : %s" % request.form['title'],
+ "",
+ "This link will bring you to the form where you will be able to vote :",
+ link,
+ "",
+ "If you think this mail is not for you, please ignore and delete it."
+ ), "\r\n")
+ server = smtplib.SMTP(SMTP_SERVER)
+ server.sendmail(EMAIL, [user['email']], BODY)
+ server.quit()