本帖最后由 Lcys 于 2017-8-9 15:55 编辑
无聊写的..
[Python] 纯文本查看 复制代码 #coding:utf-8
import urllib2
from json import *
import smtplib
from email.mime.text import MIMEText
import time
def send_mail(rev):
sender = '[url=mailto:root@phpinfo.me]root@phpinfo.me[/url]' #发送者邮箱
receiver = rev
subject = '你来了' #邮件标题
smtpserver = 'smtp.qq.com' #smtp服务器地址
username = '[url=mailto:root@phpinfo.me]root@phpinfo.me[/url]' #邮箱账号
password = '' #这里改成你的邮箱密码
msg = MIMEText('<html><h1>你好,欢迎访问我的空间</h1></html>','html','utf-8')
msg['Subject'] = subject
msg['From'] = "Lcy<[url=mailto:root@phpinfo.me]root@phpinfo.me[/url]>" #发送者
try:
smtp = smtplib.SMTP()
smtp.connect(smtpserver)
smtp.login(username, password)
smtp.sendmail(sender, receiver, msg.as_string())
smtp.quit()
return True
except Exception, e:
print str(e)
return False
def getLastQQ():
try:
sid = ""#这里填你获取到的qq sid,怎么获取请百度
qq = "1141056911" #这里改成你的qq号
url = 'http://m.qzone.com/mqz_get_visitor?g_tk=692305309&res_mode=0&res_uin='+ qq +'&offset=0&count=100&page=1&format=json&t=1441091004488&sid=' + sid
response = urllib2.urlopen(url, timeout=1)
json_str = response.read()
#print json_str
d = JSONDecoder().decode(json_str)
lastqq = d['data']['list'][0]['uin']
except Exception,e:
print e
return False
return str(lastqq)
if __name__ == '__main__' :
while True:
qq = getLastQQ()
if not qq:
print u'超时'
continue
qq_mail = getLastQQ() + "@qq.com"
f = open("db.txt","r")
db = f.read()
f.close()
if qq_mail in db:
print u"跳过"
else:
f = open("db.txt","a")
f.write(qq_mail + "\r\n")
f.close()
print u"发送邮件:" + qq_mail
if send_mail(qq_mail):
print u"发送成功"
else:
print u"发送失败"
time.sleep(2)
当有人访问你空间时就会自动给他发邮件
|