File_attack记录

GITHUB链接:github source

回顾与记录:

1、多线程。

python多线程是后面在添加socket服务器的时候才用到的。使用的是threading.Thread类继承的办法实现。

使用了生产者和消费者模式。 在这里是使用sys_status作为 产品。 当sys_status为false时,停止生产和消费。整个程序结束。

 

2、多附件的添加:

attach为['file_dir',"file_dir2']

attach应该为已经过滤过的文件目录list

每次添加的文件也不宜过多,过大。

这里是emailclient,只做发送的事,所以过滤都是在传入attach参之前需要解决的问题。

 for f in attach:
    #open with 'rb' to read non-text file
       with open(f,'rb') as f_attach:
           part = MIMEBase('application', 'octet-stream')
           part.set_payload(f_attach.read())
           Encoders.encode_base64(part)
           part.add_header('Content-Disposition',
                            'attachment; filename=""%s"' %os.path.basename(f))
           msg.attach(part)
   try:

       mailServer = smtplib.SMTP("smtp.qq.com")
       mailServer.login(gmail_user, gmail_pwd)
       mailServer.sendmail(gmail_user, to, msg.as_string().encode('utf-8'))
       mailServer.close()
   except KeyboardInterrupt:
       sys.exit()

 

posted @ 2015-09-18 10:31  _Doraemon  阅读(210)  评论(0编辑  收藏  举报