”
基本思路跟案例二类似 , 不过多展开讲 , 只复习两个知识点 。要判断标题是否有“奖金”二字:
with Imbox('imap.88.com', 'test@88.com', password, ssl=True) as imbox: all_inbox_messages = imbox.messages() for uid, message in all_inbox_messages: title = message.subject if '奖金' in title: pass
红旗标记邮件也删除邮件一样 , 也是基于邮箱编号 uid 的 , 具体代码举例:
for uid, message in all_inbox_messages: if 满足某种条件的邮件: imbox.mark_flag(uid)
故案例三的完整代码如下:
import keyringfrom imbox import Imboximport datetimefrom openpyxl import Workbookworkbook = Workbook() sheet = workbook.activeheading = ['邮件名', '发件人姓名', '发件人邮箱', '发送日期', '发送时间', '邮件正文', '附件']sheet.append(heading)password = keyring.get_password('88mail', 'test@88.com')with Imbox('imap.88.com', 'test@88.com', password, ssl=True) as imbox: all_inbox_messages = imbox.messages() for uid, message in all_inbox_messages: title = message.subject if '奖金' in title: # 判断标题是否含指定内容 name = message.sent_from[0]['name'] email = message.sent_from[0]['email'] GMT_FORMAT = '%a, %d %b %Y %H:%M:%S +0800 (GMT+08:00)' email_datetime = str(datetime.datetime.strptime(message.date, GMT_FORMAT)) email_date = email_datetime.strip()[0] email_time = email_datetime.strip()[1] text = message.body['plain'] attachment_lst = [] attachments = '' if message.attachments: for attachment in message.attachments: attachment_lst.append(attachment['filename']) attachments = ', '.join(attachment_lst) sheet.append([title, name, email, email_date, email_time, text, attachments]) imbox.mark_flag(uid) # 在此处标记符合要求的邮件 workbook.save('xxxxx.xlsx')
以上就是通过Python实现邮件管理自动化的三个实用案例 , 完整代码都已经给出 , 感兴趣的读者可以自行尝试!
推荐阅读
- 从失败到成功的励志故事?励志小故事成功在于坚持_1
- 青桔子怎么做饮料,桔子太青怎么放黄
- 一则励志小故事?一则励志小故事_1
- 跟在身后的小女孩读后感,读后感的格式简单的说
- 电动车|抢宏光mini风头:小电驴重新火起来了
- 到底孕妇吃牛蛙好么
- 男人梦见自己生小孩是什么意思 男人梦见自已生孩子
- 智能手机|天玑8000性能小金刚 Redmi Note 12要改名?卢伟冰在线征名
- 普洱糯米香小沱茶,普洱沱茶的形状
- 土卫六距离地球 土卫六与地球大小比较