Есть скрипт, который отправляет файл всем пользователям из бд. Но получатели видят всех остальных реципиентов. Как их скрыть?
from flask import Flask, render_template, make_response
from flask_celery import make_celery
from flask_sqlalchemy import SQLAlchemy
from flask_mail import Mail, Message
import os
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///subscribe.db'
app.config['MAIL_SERVER'] = 'mail.post.com'
app.config['MAIL_PORT'] = 25
app.config['MAIL_USERNAME'] = 'UserName'
app.config['MAIL_PASSWORD'] = 'Secret'
db = SQLAlchemy(app)
celery = make_celery(app)
mail = Mail(app)
class Subscribe(db.Model):
id = db.Column('id', db.Integer, primary_key=True)
email = db.Column('email', db.String(50), unique=True, nullable=False)
company = db.Column(db.String(50), nullable=False)
def __repr__(self):
return f"Subscribe('{self.company}', '{self.email}')"
@app.route('/sendmail', methods=['GET', 'POST'])
def index():
with app.app_context():
theuser = Subscribe.query.filter(Subscribe.id).all()
msg = Message('Hello', sender='flask@post.com', recipients=[theuser.email for theuser in Subscribe.query.all()])
msg.body = "testing"
msg.html = "<b>testing</b>"
with app.open_resource(r"C:\dir\worry_cat.jpg") as fp:
msg.attach("image.png", "image/png", fp.read())
for theuser in Subscribe.query.all():
mail.send(msg)
return 'Message sent!'