from database.database import get_session from database.tcontentdispatch.curd import get_contents_to_dispatch, finish_contents_to_dispatch from database.tscheduler.model import TScheduler from log.log_manager import log from mail.mail_manager import send_mail def send_reference_message_mail_task(scheduler: TScheduler): with get_session() as db: # 获取需要发送的内容列表 dispatch_contents = get_contents_to_dispatch(db) # 发送邮件 ids = [] for dispatch_content in dispatch_contents: subject = dispatch_content.title content = dispatch_content.content send_mail(subject, dispatch_content.content) ids.append(dispatch_content.id) log(f"send mail success with title {subject}, content {content[:20]}.") if dispatch_content.ai_content: send_mail(subject + '[AI]', dispatch_content.ai_content) log(f"send ai content mail success with title {subject}, content {dispatch_content.ai_content[:20]}.") # 更新数据库 finish_contents_to_dispatch(db, ids) if __name__ == '__main__': send_reference_message_mail_task(TScheduler())