zoukankan      html  css  js  c++  java
  • 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()
    

  • 相关阅读:
    php的函数
    php字符串
    PDA触屏的终极解决办法
    数字万用表 选购指南
    WindowsXp Sp2 英文版
    访问局域网某台电脑时提示:无法访问,你可能没有权限使用网络资源.的解决办法
    中华人民共和国国家标准职工工伤与职业病致残程度鉴定
    删除所有设备驱动的批处理
    如何制作Win XP操作系统映像文件
    使用批处理和devcon.exe来控制 Windows 的设备
  • 原文地址:https://www.cnblogs.com/kai-/p/13858372.html
Copyright © 2011-2022 走看看