本文整理汇总了Python中gmail.Gmail.sent_mail方法的典型用法代码示例。如果您正苦于以下问题:Python Gmail.sent_mail方法的具体用法?Python Gmail.sent_mail怎么用?Python Gmail.sent_mail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gmail.Gmail
的用法示例。
在下文中一共展示了Gmail.sent_mail方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: EmailHandler
# 需要导入模块: from gmail import Gmail [as 别名]
# 或者: from gmail.Gmail import sent_mail [as 别名]
class EmailHandler():
def __init__(self, username, password ):
self.g = Gmail()
self.g.login(username, password)
def logout(self):
self.g.logout()
def get_sent_mail(self):
return self.g.sent_mail()
def store_emails(self, start_date , store_at):
'''
Download the emails and store them in a plain text file separated by "===" string
'''
all_emails = []
for message in self.get_sent_mail().mail(after=start_date):
message.fetch()
for line in message.body.split('\r\n'):
#do some cleaning before storing the emails
if "-------- Original Message --------" in line:
break
if "---------- Forwarded message ----------" in line:
break
line = re.sub("\d+", "", line)
line = re.sub('<[^>]*>', '', line)
if line and line[0] != '>' and line[0] != '<' : #ignore quoting previous email or http links
all_emails.append(line)
all_emails.append("="*30)
#save the emails
f = open(store_at,"wr+")
f.write('\n'.join(all_emails))
f.close()
print "Done getting and storing emails"