task: add send common mail task
All checks were successful
Gitea Actions Demo / deploy (push) Successful in 11s
All checks were successful
Gitea Actions Demo / deploy (push) Successful in 11s
This commit is contained in:
24
task/common_mail/common_mail_task.py
Normal file
24
task/common_mail/common_mail_task.py
Normal file
@ -0,0 +1,24 @@
|
||||
from database.tscheduler.model import TScheduler
|
||||
from mail.mail_manager import send_mail
|
||||
from config.database import SessionLocal
|
||||
from models import Article
|
||||
from utils import logger
|
||||
|
||||
|
||||
def common_mail_task(scheduler: TScheduler):
|
||||
with SessionLocal() as db:
|
||||
# 获取需要发送的内容列表
|
||||
articles = db.query(Article).filter(Article.used == False).all()
|
||||
# 发送邮件
|
||||
for article in articles:
|
||||
subject = article.title
|
||||
content = article.content
|
||||
send_mail(subject, content, receiver_email="changsongd@126.com")
|
||||
logger.info(f"send mail success with title {subject}, content {content[:20]}.")
|
||||
# 更新数据库
|
||||
for article in articles:
|
||||
article.used = True
|
||||
db.commit()
|
||||
|
||||
if __name__ == '__main__':
|
||||
common_mail_task(TScheduler())
|
||||
Reference in New Issue
Block a user