一年前写的一个脚本, 通过爬虫技术,将网站页面上出现的email地址给扒下来,
然后进行重发邮件, 由于邮箱的安全机制, 可能会进行阻拦(可以考虑怎么避免这样).........
附代码:
main.py
#! /usr/bin/python
# -*- coding: utf-8 -*-
import re, urllib, sys, SendMail
patt2 = ‘\w+@\w+\.com‘
pattern = ‘[\w.-]+@[\w.-]+\.\w+‘
if len(sys.argv) < 2:
print "print mail --help for more help"
sys.exit(1)
if sys.argv[1].startswith("--help"):
print ‘‘‘mail [url]
send email to the catched mail address‘‘‘
sys.exit(1)
else:
url = sys.argv[1]
info = urllib.urlopen(url).read()
mailinfo = re.findall(pattern, info)
hostname = raw_input("input the hostname you want:")
mailsub = raw_input("input the subject of you mail:")
mailcontext = raw_input("input the context you send:")
for mailaddress in mailinfo:
if SendMail.send_mail(hostname, mailaddress, mailcontext, mailsub) == 1:
print "成功向%s发送邮件" % mailaddress
else:
print "发送到%s的邮件发生错误" % mailaddress其中的mail 主机 和用户密码可以手动进行改动!
#! /usr/bin/python
import smtplib, sys
from email.mime.text import MIMEText
def send_mail(mailfrom, mailto, context, sub):
mail_host = "smtp.qq.com" //可以改动
mail_usr = "872639280@qq.com"
mail_passwd = "*****"
msg = MIMEText(context)
msg[‘Subject‘] = sub
msg[‘From‘] = mailfrom
msg[‘To‘] = mailto
try:
s = smtplib.SMTP()
s.connect(mail_host)
s.login(mail_usr, mail_passwd)
s.sendmail(mail_usr, mailto, msg.as_string())
s.close()
return 1
except:
return 0
if __name__ == "__main__":
if send_mail("HuntingGo@Hunting.Go", "872639280@qq.com", "miss u", "miss u"):
print "send success!"
else:
print "failed to send!"
原文:http://blog.csdn.net/huntinggo/article/details/22597079