夕阳的金辉把绿色的林海染成金黄一片。火红的太阳慢慢地西落了,归鸟们纷纷从我头上飞过,飞回到它们的小巢。一轮明月从东方静悄悄地升上来。夜空中美丽的星星,似乎在眨着眼睛对我说:夜,来了!
本文实例讲述了Python接收Gmail新邮件并发送到gtalk的方法。分享给大家供大家参考。具体实现方法如下:
#!/usr/bin/env python # -*- coding: utf-8 -*- import imaplib import string, random import StringIO, rfc822 import email from google.appengine.api import xmpp SERVER1 = "imap.gmail.com" USER = "yeah" PASSWORD = "ohmyga" # connect to server server = imaplib(SERVER1, 993) # login server.login(USER, PASSWORD) server.select() # list items on server status, data = server.search(None, "(UNSEEN)") mails = data[0].split() if data[0] != '': print "has mails" user_address = 'wangnaide@gmail.com' for num in data[0].split(): tpe, raw_msg = server.fetch(num, '(RFC822)') msg = email.message_from_string(raw_msg[0][1]) #Subjects sbj, ecode = email.Header.decode_header(msg['subject'])[0] #from, sender frm = '' for fts, ecode in email.Header.decode_header(msg['from']): frm = frm + fts if xmpp.get_presence(user_address): xmpp.send_message(user_address, frm + ':' + sbj) server.store(num, '+FLAGS', '\\SEEN') #print frm + ":" + sbj server.close() server.logout()
希望本文所述对大家的Python程序设计有所帮助。
到此这篇关于Python接收Gmail新邮件并发送到gtalk的方法就介绍到这了。前有阻碍,奋力把它冲开,运用炙热的激情,转动心中的期待,血在澎湃,吃苦流汗算什么。更多相关Python接收Gmail新邮件并发送到gtalk的方法内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!