原创作者: towjzhou
阅读:1317次
评论:0条
更新时间:2011-06-01
GSend.py
python 代码
python 代码
- """GMail file sender: Send a file use GMail.
- """
- from __future__ import with_statement
- import os
- import sys
- from smtplib import SMTP
- from email.MIMEMultipart import MIMEMultipart
- from email.mime.application import MIMEApplication
- import time
- if len(sys.argv) < 2:
- print 'Usage: python %s <file path>' % os.path.basename(sys.argv[0])
- sys.exit(-1)
- config = {
- 'from': "XXX XXX@gmail.com
- 'to': 'XXX@hotmail.com',
- 'subject': '[gsend]Send file %s' % sys.argv[1],
- 'file': sys.argv[1],
- 'server': 'smtp.gmail.com',
- 'port': 587,
- 'username': 'XXX@gmail.com',
- 'password': 'xxxxxx',
- }
- print 'Preparing...',
- message = MIMEMultipart( )
- message['from'] = config['from']
- message['to'] = config['to']
- message['Reply-To'] = config['from']
- message['Subject'] = config['subject']
- message['Date'] = time.ctime(time.time())
- message['X-Priority'] = '3'
- message['X-MSMail-Priority'] = 'Normal'
- message['X-Mailer'] = 'Microsoft Outlook Express 6.00.2900.2180'
- message['X-MimeOLE'] = 'Produced By Microsoft MimeOLE V6.00.2900.2180'
- with open(config['file'], 'rb') as f:
- file = MIMEApplication(f.read())
- file.add_header('Content-Disposition', 'attachment', filename=os.path.basename(config['file']))
- message.attach(file)
- print 'OK'
- print 'Logging...',
- smtp = SMTP(config['server'], config['port'])
- smtp.ehlo()
- smtp.starttls()
- smtp.ehlo()
- smtp.login(config['username'], config['password'])
- print 'OK'
- print 'Sending...',
- smtp.sendmail(config['from'], [config['from'], config['to']], message.as_string())
- print 'OK'
- smtp.close()
- time.sleep(1)
python 代码
- @REM put this file in to windows "Send to" folder
- python c:/gsend.py "%1"
- @pause
然后就是右键->WinRAR->压缩成一个文件->右键->Send to->gsend.bat
评论 共 0 条 请登录后发表评论