есть простенькая база с пользователями, которым нужно отправлять мессаджи
class Subscribe(db.Model):
id = db.Column('id', db.Integer, primary_key=True)
company = db.Column('company', db.String(50))
email = db.Column('email', db.String(50))
Есть скрипт, который отправляет сообщение, в данном случае первому пользователю бд
@app.route('/sendmail', methods=['POST'])
def index():
theuser = Subscribe.query.filter(Subscribe.id).first()
msg = Message('Hello', sender='[email protected]', recipients=[theuser.email])
with app.open_resource(r"C:\py\image.jpg") as fp:
msg.attach("image.png", "image/png", fp.read())
mail.send(msg)
return 'Message sent!'
Подскажите, как отправить сообщение всем пользователям бд
for theuser in Subscribe.query.all():
?Subscribe
у поляemail
значение"email"
? Попробуйте, например, через sql повторить его же:select * from Subscribe where email = 'email'
emails = [theuser.email for theuser in Subscribe.query.all()]