原创作者: towjzhou   阅读:1299次   评论:0条   更新时间:2011-06-01    
GSend.py

python 代码
 
  1. """GMail file sender: Send a file use GMail. 
  2. """  
  3.   
  4. from __future__ import with_statement  
  5. import os  
  6. import sys  
  7. from smtplib import SMTP  
  8. from email.MIMEMultipart import MIMEMultipart  
  9. from email.mime.application import MIMEApplication  
  10. import time  
  11.   
  12. if len(sys.argv) < 2:  
  13.     print 'Usage: python %s <file path>' % os.path.basename(sys.argv[0])  
  14.     sys.exit(-1)  
  15.   
  16. config =  {  
  17.     'from': "XXX XXX@gmail.com
  18.     'to': 'XXX@hotmail.com',  
  19.     'subject': '[gsend]Send file %s' % sys.argv[1],  
  20.     'file': sys.argv[1],  
  21.     'server': 'smtp.gmail.com',  
  22.     'port': 587,  
  23.     'username': 'XXX@gmail.com',  
  24.     'password': 'xxxxxx',  
  25. }  
  26.   
  27. print 'Preparing...',  
  28.   
  29. message = MIMEMultipart( )  
  30. message['from'] = config['from']  
  31. message['to'] = config['to']  
  32. message['Reply-To'] = config['from']  
  33. message['Subject'] = config['subject']  
  34. message['Date'] = time.ctime(time.time())  
  35.   
  36. message['X-Priority'] =  '3'  
  37. message['X-MSMail-Priority'] =  'Normal'  
  38. message['X-Mailer'] =  'Microsoft Outlook Express 6.00.2900.2180'  
  39. message['X-MimeOLE'] =  'Produced By Microsoft MimeOLE V6.00.2900.2180'  
  40.   
  41. with open(config['file'], 'rb') as f:  
  42.     file = MIMEApplication(f.read())  
  43. file.add_header('Content-Disposition', 'attachment', filename=os.path.basename(config['file']))  
  44. message.attach(file)  
  45.   
  46. print 'OK'  
  47. print 'Logging...',  
  48.   
  49. smtp = SMTP(config['server'], config['port'])  
  50. smtp.ehlo()  
  51. smtp.starttls()  
  52. smtp.ehlo()  
  53. smtp.login(config['username'], config['password'])  
  54.   
  55. print 'OK'  
  56. print 'Sending...',  
  57.   
  58. smtp.sendmail(config['from'], [config['from'], config['to']], message.as_string())  
  59.   
  60. print 'OK'  
  61.   
  62. smtp.close()  
  63.   
  64. time.sleep(1)  
GSend.bat
python 代码
 
  1. @REM put this file in to windows "Send to" folder  
  2.   
  3. python c:/gsend.py "%1"  
  4. @pause  

然后就是右键->WinRAR->压缩成一个文件->右键->Send to->gsend.bat
评论 共 0 条 请登录后发表评论

发表评论

您还没有登录,请您登录后再发表评论

文章信息

Global site tag (gtag.js) - Google Analytics