首页 > 其他 > 详细

File_attack记录

时间:2015-09-18 11:31:58      阅读:181      评论:0      收藏:0      [点我收藏+]

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()

 

File_attack记录

原文:http://www.cnblogs.com/-Doraemon/p/4818491.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!