Пример #1
0
def send_mail(to_list,sub,content):
    #设置服务器,用户名、口令以及邮箱的后缀
    mail_host="smtp.163.com"
    mail_user="******"
    mail_pass="******"
    mail_postfix="163.com"
    me=mail_user+"<"+mail_user+"@"+mail_postfix+">"
    msg = MIMEText(content,"html","utf-8")
    msg['Subject'] = sub
    msg['From'] = me
    msg['To'] = to_list
    try:
        s = smtplib.SMTP()
        s.connect(mail_host)
        s.login(mail_user,mail_pass)
        s.sendmail(me, to_list, msg.as_string())
        s.close()
        print '1'
        print to_list +" " + sub + " 发送成功"
        return True
    except Exception, e:
        print '2'
        print str(e)
        ylib.log_pf(str(e))
        print to_list +" " + sub + " 发送失败"
        return False
Пример #2
0
def cycle():
    mylist = get_hitsz()
    post_list = []
    maxid = get_maxid()
    tmax  = maxid
    for item in mylist:
        item_id = get_strid(item["href"])
        if(item_id > maxid): post_list.append(item)
        if(item_id > tmax): tmax = item_id
    ylib.log_pf("new news list length : " + str(len(post_list)) );
    if len(post_list) > 0:
        ylib.log_pf("新增加新闻")
        for item in post_list: ylib.log_pf(item["text"].replace(".","") + "  " + item["href"])
        mystr = "<h3> ^V^ </h3>"
        for item in post_list: mystr += "<a href ='" + item["href"] + "'>"+ "<p>" + item["text"] + "</p>" + "</a>"
        if tmax != maxid: write_maxid(tmax)
        import my_email as me
        import user
        subject = "Fresh news in : " + str(ylib.get_now_time())
        for item in user.users:
            import time
            time.sleep(5)
            if me.send_mail(item.email,subject,mystr) == 1: ylib.log_pf(item.name + " 发送成功")
            else: ylib.log_pf(item.name + " 发送不成功")
Пример #3
0
    for item in mylist:
        item_id = get_strid(item["href"])
        if(item_id > maxid): post_list.append(item)
        if(item_id > tmax): tmax = item_id
    ylib.log_pf("new news list length : " + str(len(post_list)) );
    if len(post_list) > 0:
        ylib.log_pf("新增加新闻")
        for item in post_list: ylib.log_pf(item["text"].replace(".","") + "  " + item["href"])
        mystr = "<h3> ^V^ </h3>"
        for item in post_list: mystr += "<a href ='" + item["href"] + "'>"+ "<p>" + item["text"] + "</p>" + "</a>"
        if tmax != maxid: write_maxid(tmax)
        import my_email as me
        import user
        subject = "Fresh news in : " + str(ylib.get_now_time())
        for item in user.users:
            import time
            time.sleep(5)
            if me.send_mail(item.email,subject,mystr) == 1: ylib.log_pf(item.name + " 发送成功")
            else: ylib.log_pf(item.name + " 发送不成功")


if __name__ == "__main__":
    while(1):
        print ylib.get_now_time()
        ylib.log_pf("开始探测数据")
        cycle()
        ylib.log_pf("探测结束")
        print "探测结束"
        import time
        time.sleep(3600*6)