def generateFeedEntry(urlContent,feed): encodeType = feed['encoding'] urlContent = urlContent.decode(encodeType).encode('utf-8') global_pattern = re.compile(feed['global_search_pattern'].replace('{%}','(.*?)').replace('{*}','.*?'),re.I|re.S|re.M) item_pattern = re.compile(feed['item_search_pattern'].replace('{%}','(.*?)').replace('{*}','.*?'),re.I|re.S|re.M) sub_pattern = re.compile(r'{%(.*?)}',re.I|re.S|re.M) globalMatch = global_pattern.search(urlContent) globalContent = globalMatch.group() globalContent = globalContent[0:len(globalContent)/4] itemList = item_pattern.findall(globalContent) print len(itemList) for i in xrange(len(itemList)-1,-1,-1): item = itemList[i] link = feed['item_link'] title = feed['item_title'] content = feed['item_content'] link = sub_pattern.sub(lambda m: str(item[int(m.group(1))-1]),link) content = sub_pattern.sub(lambda m: str(item[int(m.group(1))-1]),content) title = sub_pattern.sub(lambda m: str(item[int(m.group(1))-1]),title) result = Entry.objects.filter(title=title) if len(result) == 0: entry = Entry(title=title,link=link,content=content,feedid=feed['id']) entry.save() if feed['mail_address']!='': send_mail(feed['mail_address'], title, link, ("smtp.163.com", 25, "*****@*****.**", "1234qwer", False)) pass pass pass
def send_messages(self, email_messages): for email in email_messages: send_mail(email.to, email.subject, email.body, (settings.EMAIL_HOST, settings.EMAIL_PORT, settings.EMAIL_HOST_USER, settings.EMAIL_HOST_PASSWORD, settings.EMAIL_USE_TLS))
def syncWeibo(request): WBLogin = weiboLogin.weiboLogin() if WBLogin.login('*****@*****.**','1234qwer')==1: urlContent = urllib2.urlopen('http://game.weibo.com/club/forum-315-1').read() soup = BeautifulSoup(urlContent) ul = soup.find('ul',{'class':'top_topics'}) lis = ul.findAll('li',{'class':''}) for li in lis: item = { 'user':li.find('div',{'class':'col1'}).find('img')['alt'], 'link':li.find('div',{'class':'no_rep_line'}).findAll('a')[1]['href'], 'tag':li.find('a',{'class':'navy_tag'}).string, 'title':li.find('div',{'class':'no_rep_line'}).findAll('a')[1].string, 'time':li.find('div',{'class':'col2'}).find('span').string } title = "[%s][%s]%s%s"%(item['time'],item['user'],item['tag'],item['title']) link = item['link'] result = Entry.objects.filter(title=title) if len(result) == 0: entry = Entry(title=title,link=link,content='',feedid=0) entry.save() send_mail("*****@*****.**", title, link, ("smtp.163.com", 25, "*****@*****.**", "1234qwer", False)) pass pass return HttpResponse("Login success!") else: return HttpResponse("Login error!") pass
def sendMail(): now = time.time() datalist = datas.select("sendmail.json",{"Time":['<=',now]}) for data in datalist: mail = data["mail"] send_mail(mail, u"事件提醒", data["Matter"],\ (config.smtpaddr, config.smtpport, config.emailaddr, config.passwdmail, False)) datas.delete("sendmail.json",{"ID":['=',data["ID"]]})
def POST(self): x = web.input() db.insert('message', name = x.name, contact = x.contact,factory = x.factory,content = x.content) indexObj = {'isJustDone':1} msg = '姓名:'+x.name+';联系方式:'+x.contact+';来自:'+x.factory+';内容:'+x.content.decode('UTF-8') send_mail(["*****","*****@qq.com"], '【金鼎恒业网站信息】来自:'+x.name+'的留言',msg, ("smtp.qq.com", 25, "******@qq.com", "*****", False)) return render.message(indexObj)
def GET(self): token = db.query("SELECT token from token")[0]['token'] celebrityList = db.select('celebrity') for one in celebrityList: #get newest mid #weibo开放平台太CD了,不让获取其他用户微博了,只能获取自己的!结果都是空了! getFeedUrl= "http://api.weibo.com/2/statuses/user_timeline.json?access_token="+token+"&source="+consumer_key+"&uid="+one['uid']+"&count=1" request = urllib2.Request(getFeedUrl) request.add_header("Authorization", authheader) handle = urllib2.urlopen(request) firstFeed = json.loads(handle.read()) feed = firstFeed['statuses'] if feed : mid = feed[0]['mid'] else : mid = '0' #campare mid hasOne = string.atoi(mid) > string.atoi(one['mid']) if hasOne : db.update('celebrity',where="uid =$uid", vars={'uid':one['uid']}, mid = mid) #sent e-mail msg = feed[0]['user']['name']+': '+feed[0]['text'].decode('UTF-8') send_mail("*****@qq.com", msg,msg, ("smtp.qq.com", 25, "****", "*****", False)) #favorites feed favoritesQuery = urllib.urlencode({"id":mid,"access_token":token,"source":consumer_key}) favoritesUrl = "http://api.weibo.com/2/favorites/create.json" favoritesReq = urllib2.Request(favoritesUrl, favoritesQuery) favoritesReq.add_header("Authorization", authheader) urllib2.urlopen(favoritesReq) #post comment 1937439635:13sis uid if one['uid'] == '1937439635' or one['uid'] == '1352528560': if one['uid'] == '1352528560' : comment = "啦啦啦~" else : comment = "13sis重现江湖~" commentQuery = urllib.urlencode({"comment":comment,"id":mid,"access_token":token,"source":consumer_key}) commentUrl = "http://api.weibo.com/2/comments/create.json" sendCmtReq = urllib2.Request(commentUrl, commentQuery) sendCmtReq.add_header("Authorization", authheader) urllib2.urlopen(sendCmtReq) #send text message textQuery = urllib.urlencode({"mobile":"1521056****","msg":msg,"encoding":"GB2312"}) textUrl = "http://inno.smsinter.sina.com.cn/sae_sms_service/sendsms.php" sendText = urllib2.Request(textUrl, textQuery) hand = urllib2.urlopen(sendText) return hand return 1
def sendSignUpMail(to, name): msg = """亲爱的{}, 欢迎加入饭团,我们的应用旨在使的您的生活更加方便和快捷。 如果你有任何意见和建议,请致信 [email protected] 。 衷心地祝福您快乐每一天。 Regards, Fantuan Team http://fantuan.sinaapp.com""" title = "欢迎加入饭团" send_mail(to, title, msg.format(name), (mail_server, mail_port, mail_from, mail_password, True))
def sendMailBy126(tolist, subject, content): from ExpPH.utils.BaseUtils import decrypt isSentMail = False mail_host = "smtp.126.com" # 发信邮箱 SMTP 服务器 mail_port = 25 # 发信邮箱 SMTP 服务器端口 mail_user = "******" # 发信邮箱账号 mail_postfix = "126.com" # 发信邮箱后缀 mail_pass = decrypt("RXhwMTIzNDU2UEg=") # 发信邮箱密码 sender = mail_user + "@" + mail_postfix # 发信者 # SAE 环境 if not isLocalEnvironment: from sae.mail import send_mail try: send_mail(tolist, subject, content, (mail_host, mail_port, sender, mail_pass, False)) isSentMail = True except Exception, e: print "发送邮件失败:", str(e)
def send_mail(self,form): receiver = form.cleaned_data['email'] content = base64.encodestring(receiver) str_url = 'http://diggg.sinaapp.com/register?p=' + content send_mail(receiver, "invite", str_url, ("smtp.163.com", 25, "*****@*****.**", "diggg1234", True))
def quick_mail(to, subject, body): send_mail(to, subject, body, config.MAIL_SMTP)
def mail(address, body): subject = u'您好,有位来自武汉高校之恋的用户向你发送了交友请求' smtp = ('smtp.googlemail.com', '465', '*****@*****.**', 'lihangcxf', True) send_mail(address, subject, body, smtp)