分类: LINUX
2010-04-17 22:13:56
用流量监视软件看了一下我另外一博客的内容后发现, 主要来访问的都是通过搜索" linux 邮件" 等关键字过来的. 相信这也是很多新手经常遇到的问题.
发一下我以前在网上找到的脚本并做了简单的修改. 相信可以满足大家的需求. 脚本是Python的, 相信在大家的Linux服务器上都是可以直接运行的, 但需要2.5版本以上.
#coding=utf-8
#! /usr/lib/python2.5/bin/python
import os
import sys
from smtplib import SMTP
from email.MIMEMultipart import MIMEMultipart
from email.mime.application import MIMEApplication
import time
def sendFildByMail(config):
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'
f=open(config['file'], 'rb')
file = MIMEApplication(f.read())
f.close()
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服务器发邮件时不需要验证登录则对下面这行加上注释
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)
if __name__ == "__main__":
if len(sys.argv) < 2:
print 'Usage: python %s ' % os.path.basename(sys.argv[0])
#sys.exit(-1)
else:
#587, 25
sendFildByMail({
'from': "eg@163.com",
'to': 'eg@uniclick.cn',
'subject': '[pysend]Send file %s' % sys.argv[1],
'file': sys.argv[1],
'server': 'smtp.163.com',
'port': 25,
'username': '********',
'password': '*********'})
wait=raw_input("end.")
可以自己去修改里面的内容来适应大家各自的需要.