2010-02-12 13 views
7

मैं एक अजगर स्क्रिप्ट अनदेखी संदेश, यह प्रक्रिया, और मार्क के रूप में देखा लाने के लिए है कि है (या पढ़ा)पायथन, आईएमएपी और जीमेल। मार्क संदेशों के रूप में देखा

मैं में प्रवेश के बाद ऐसा करते हैं:

typ, data = self.server.imap_server.search(None, '(UNSEEN)') 

    for num in data[0].split(): 
     print "Mensage " + str(num) + " mark" 
     self.server.imap_server.store(num, '+FLAGS', '(SEEN)') 

पहली समस्या यह है कि, खोज सभी संदेशों को लौटाती है, न केवल संयुक्त राष्ट्र। दूसरी समस्या यह है कि संदेश SEEN के रूप में चिह्नित नहीं हैं।

क्या कोई मुझे इस के साथ हाथ दे सकता है?

धन्यवाद!

उत्तर

3

मुझे लगता है कि झंडा नाम बैकस्लैश, जैसे के साथ शुरू करने की जरूरत है: \ देखा

12
import imaplib 
obj = imaplib.IMAP4_SSL('imap.gmail.com', '993') 
obj.login('user', 'password') 
obj.select('Inbox') <--- it will select inbox 
typ ,data = obj.search(None,'UnSeen') 
obj.store(data[0].replace(' ',','),'+FLAGS','\Seen') 
0

मैं imaplib के साथ इतना परिचित नहीं हूँ, लेकिन मैं imapclient मॉड्यूल

import imapclient,pyzmail,html2text 
from backports import ssl 
context=ssl.SSLContext(ssl.PROTOCOL_TLSv1_2) 

iobj=imapclient.IMAPClient('outlook.office365.com', ssl=True, ssl_context=context) 
iobj.login(uname,pwd)# provide your username and password 
iobj.select_folder('INBOX',readonly=True)# Selecting Inbox. 

unread=iobj.search('UNSEEN')# Selecting Unread messages, you can add more search criteria here to suit your purpose.'FROM', 'SINCE' etc. 
print('There are: ',len(unread),' UNREAD emails') 

for i in unread: 

    mail=iobj.fetch(i,['BODY[]'])#I'm fetching the body of the email here. 
    mcontent=pyzmail.PyzMessage.factory(mail[i][b'BODY[]'])#This returns the email content in HTML format 
    subject=mcontent.get_subject()# You might not need this    
    receiver_name,receiver_email=mcontent.get_address('from') 
    mail_body=html2text.html2text(mcontent.html_part.get_payload().decode(mcontent.html_part.charset))# This returns the email content as text that you can easily relate with. 
साथ अच्छी तरह से यह लागू

मान लें कि मैं केवल अपठित ईमेल के माध्यम से जाना चाहता हूं, प्रेषक को जवाब देना और ईमेल को पढ़ने के रूप में चिह्नित करना चाहता हूं। मैं लिखने और उत्तर भेजने के लिए यहां से smtp फ़ंक्शन को कॉल करूंगा।

import smtplib 
smtpobj=smtplib.SMTP('smtp.office365.com',587) 
smtpobj.starttls() 
smtpobj.login(uname,pwd)# Your username and password goes here. 
sub='Subject: '+str(subject)+'\n\n'# Subject of your reply 
msg='Thanks for your email! You're qualified for the next round' #Some random reply :(
fullmsg=sub+new_result 
smtpobj.sendmail(uname,test,fullmsg)# This sends the email. 
iobj.set_flags(i,['\\Seen','\\Answered'])# This marks the email as read and adds the answered flag 
iobj.append('Sent Items', fullmsg)# This puts a copy of your reply in your Sent Items. 

iobj.logout() 
smtpobj.logout() 

मुझे आशा है कि इस मदद करता है

संबंधित मुद्दे