• smtplib 邮件模块


    import smtplib
    from email.mime.multipart import MIMEMultipart
    from email.mime.text import MIMEText
    from email.mime.application import MIMEApplication
    from live.settings import SEND_HOUR_TIME, SEND_MINUTE_TIME, T_SEND_HOUR_TIME, T_SEND_MINUTE_TIME
    
    username = 'kkkse@163.com'
    password = 'SPICGNRLY'
    sender = username
    receivers = ','.join(['sjdfo@163.net'])  # 接收者
    # receivers = ','.join(['nnnn@163.com'])  # 接收者
    
    from apscheduler.schedulers.blocking import BlockingScheduler
    sc = BlockingScheduler()
    
    @sc.scheduled_job('cron', day_of_week='*', hour=SEND_HOUR_TIME, minute=f'{SEND_MINUTE_TIME}', second='00')
    def run():
        msg = MIMEMultipart()
        msg['Subject'] = '主题'
        msg['From'] = sender
        msg['To'] = receivers
    
        puretext = MIMEText('')
        msg.attach(puretext)
    
        xlsxpart = MIMEApplication(open('data.xlsx', 'rb').read())
        xlsxpart.add_header('Content-Disposition', 'attachment', filename='data.xlsx')
        msg.attach(xlsxpart)
    
        client = smtplib.SMTP()
        client.connect('smtp.163.com')
        client.login(username, password)
        client.sendmail(sender, receivers, msg.as_string())
        client.quit()
        print('邮件发送成功!')
    
    
    sd = BlockingScheduler()
    
    @sd.scheduled_job('cron', day_of_week='*', hour=SEND_HOUR_TIME, minute=f'{SEND_MINUTE_TIME}', second='00')
    def run():
        msg = MIMEMultipart()
        msg['Subject'] = '主题'
        msg['From'] = sender
        msg['To'] = receivers
    
        puretext = MIMEText('')
        msg.attach(puretext)
    
        xlsxpart = MIMEApplication(open('data1.xlsx', 'rb').read())
        xlsxpart.add_header('Content-Disposition', 'attachment', filename='data1.xlsx')
        msg.attach(xlsxpart)
    
        client = smtplib.SMTP()
        client.connect('smtp.163.com')
        client.login(username, password)
        client.sendmail(sender, receivers, msg.as_string())
        client.quit()
        print('邮件发送成功!')
    
    
    send_email1 = sc.start
    send_email2 = sd.start
    
    
    

    定时发送

    from live.test import start1, start2
    
    import threading
    
    def main():
        t1 = threading.Thread(target=start1)		# 函数名,不带括号
        t2 = threading.Thread(target=start2)
        t1.start()
        t2.start()
    
    if __name__ == '__main__':
        main()
    

  • 相关阅读:
    转:1分钟解决git clone 速度慢的问题
    进程冻结学习笔记
    RT调度学习笔记(1)
    tracer ftrace笔记(2)——添加与使用
    Regeultor内核文档翻译_学习笔记
    一、Linux cpuidle framework(1)_概述和软件架构
    Python 将私有包自动上传Nexus私服
    Pychram 取消自动添加版本控制
    Python 3DES CBC 模式加密解密
    1588. 所有奇数长度子数组的和
  • 原文地址:https://www.cnblogs.com/kai-/p/13858372.html
Copyright © 2020-2023  润新知