我想标记 imaplib 看到的 gmail 邮件
I want to mark the gmail messages Seen by imaplib
我想通过 python 解析一些 gmail 电子邮件。
我希望在阅读消息时将其显示出来。
我输入了这段代码,但它没有被标记为可见?
#read or seen email
mail.store(i,'+FLAGS', '\Seen')
你知道我如何让电子邮件保持查看状态吗?
mport imaplib,dateutil.parser
import email
###################### mail read code ###################
mail=imaplib.IMAP4_SSL('imap.gmail.com',993) #SMTPは993,POPは995
mail.login('example@co.jp','12123')
mail.select('example.jp',readonly=True) #mailbox select read only
#UNSEEN read mail
type,data=mail.search(None,'UNSEEN')
for i in data[0].split(): #data loop
ok,x=mail.fetch(i,'RFC822') #mail information get
ms=email.message_from_string(x[0][1].decode('iso-2022-jp')) #pass get
#from get
ad=email.header.decode_header(ms.get('From'))
ms_code=ad[0][1]
if(ms_code!=None):
address=ad[0][0].decode(ms_code)
address+=ad[1][0].decode(ms_code)
else:
address=ad[0][0]
#Title get
sb=email.header.decode_header(ms.get('Subject'))
ms_code=sb[0][1]
if(ms_code!=None):
sbject=sb[0][0].decode(ms_code)
else:
ms_code=sb[1][1]
sbject=sb[1][0].decode(ms_code)
#body get
maintext=ms.get_payload()
#read email
mail.store(i,'+FLAGS', '\Seen')
print(sbject)
print(address)
print(maintext)
我想您可能想阅读 Gmail API reference on labels but very likely you are in need to remove labels UNREAD
from the e-mail you want to be marked as read. For that you would have to use REST API or googleapiclient
Python 图书馆。
如果您以只读方式打开邮箱,则无法对其进行更改,包括存储标志:
mail.select('example.jp',readonly=True) #mailbox
删除只读标志。
我想通过 python 解析一些 gmail 电子邮件。 我希望在阅读消息时将其显示出来。 我输入了这段代码,但它没有被标记为可见?
#read or seen email
mail.store(i,'+FLAGS', '\Seen')
你知道我如何让电子邮件保持查看状态吗?
mport imaplib,dateutil.parser
import email
###################### mail read code ###################
mail=imaplib.IMAP4_SSL('imap.gmail.com',993) #SMTPは993,POPは995
mail.login('example@co.jp','12123')
mail.select('example.jp',readonly=True) #mailbox select read only
#UNSEEN read mail
type,data=mail.search(None,'UNSEEN')
for i in data[0].split(): #data loop
ok,x=mail.fetch(i,'RFC822') #mail information get
ms=email.message_from_string(x[0][1].decode('iso-2022-jp')) #pass get
#from get
ad=email.header.decode_header(ms.get('From'))
ms_code=ad[0][1]
if(ms_code!=None):
address=ad[0][0].decode(ms_code)
address+=ad[1][0].decode(ms_code)
else:
address=ad[0][0]
#Title get
sb=email.header.decode_header(ms.get('Subject'))
ms_code=sb[0][1]
if(ms_code!=None):
sbject=sb[0][0].decode(ms_code)
else:
ms_code=sb[1][1]
sbject=sb[1][0].decode(ms_code)
#body get
maintext=ms.get_payload()
#read email
mail.store(i,'+FLAGS', '\Seen')
print(sbject)
print(address)
print(maintext)
我想您可能想阅读 Gmail API reference on labels but very likely you are in need to remove labels UNREAD
from the e-mail you want to be marked as read. For that you would have to use REST API or googleapiclient
Python 图书馆。
如果您以只读方式打开邮箱,则无法对其进行更改,包括存储标志:
mail.select('example.jp',readonly=True) #mailbox
删除只读标志。