import chz_gmaillib import dataset import datetime db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4') lst=[] cliend_id='db' campaign='20220305-test' cursor=db.query('select id,email,title from mail_list where enabled=1 and email not in (select email from emaillog where campaign="'+campaign+'") order by rand() limit 1') for c in cursor: lst.append(c) table=db['emaillog'] for c in lst: mailobj={} mailobj['toaddr']=c['email'] mailobj['title']=c['title']+'x ChoozMo 合作洽談 ' display={} display['custname']=c['title'] display['client']=c['id'] display['email']=mailobj['toaddr'] display['campaign']=campaign mailobj['display']=display chz_gmaillib.mail_to_other(mailobj) table.insert({'email':c['email'],'title':c['title'],'cliend_id':cliend_id,'campaign':campaign,'dt':datetime.datetime.now()})