import keyring
pw=keyring.get_password('yagmail','[email protected]') #获取注册码
from imbox import Imbox #导入imbox
with Imbox('smtp.qq.com','[email protected]',pw) as imbox:
all_messages=imbox.messages()
for uid,message in all_messages:
print('uid',uid)
print('主题',message.subject)
print('文本格式',message.body['plain'])
print('发件人:',message.sent_from)
print('收件人:', message.sent_to)
print('时间:',message.date)
print('成功') #读取成功
读取不同类型的邮件
1.未读取邮件 :all_messages=imbox.messages(unread=True)
2.红旗(星)邮件:all_messages=imbox.messages(flagged=True)
3.某人发的:all_messages=imbox.messages(sent_from='[email protected]')
4.某人收的:all_messages=imbox.messages(sent_to='[email protected]')
import keyring
pw=keyring.get_password('yagmail','[email protected]') #获取注册码
from imbox import Imbox #导入imbox
with Imbox('smtp.qq.com','[email protected]',pw) as imbox:
all_messages=imbox.messages(flagged=True) #读取不同类型的文件在这加判断条件
for uid,message in all_messages:
print('uid',uid)
print('主题',message.subject)
print('文本格式',message.body['plain'])
print('发件人:',message.sent_from)
print('收件人:', message.sent_to)
print('时间:',message.date)
print('成功') #读取成功
根据时间读取不同的邮件
1.某天之前:date_lt
2.某天之后:date_gt
3某一天:date_on
import keyring,datetime
pw=keyring.get_password('yagmail','[email protected]') #获取注册码
from imbox import Imbox #导入imbox
with Imbox('smtp.qq.com','[email protected]',pw) as imbox:
all_messages=imbox.messages(date__on=datetime.date(2021,2,8)) #读取不同时间的文件在这加判断条件
for uid,message in all_messages:
print('uid',uid)
print('主题',message.subject)
print('文本格式',message.body['plain'])
print('发件人:',message.sent_from)
print('收件人:', message.sent_to)
print('时间:',message.date)
print('成功') #读取成功
将未读邮件标记为已读邮件
import keyring,datetime
pw=keyring.get_password('yagmail','[email protected]') #获取注册码
from imbox import Imbox #导入imbox
with Imbox('smtp.qq.com','[email protected]',pw) as imbox:
all_messages=imbox.messages(unread=True) #读取未读邮件
for uid,message in all_messages:
imbox.mark_seen(uid)
将制定邮件删除(所有已读情况下)
import keyring,datetime
pw=keyring.get_password('yagmail','[email protected]') #获取注册码
from imbox import Imbox #导入imbox
with Imbox('smtp.qq.com','[email protected]',pw) as imbox:
all_messages=imbox.messages() #读取未读邮件
for uid,message in all_messages:
if message.subject=='~~~~':#要删除邮件主题名
imbox.delete(uid)