• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > python操作gmail实例

python操作gmail实例

作者:shichen2014 字体:[增加 减小] 来源:互联网

shichen2014 通过本文主要向大家介绍了gmail,谷歌gmail,gmail邮箱注册,gmail邮箱,gmail邮箱登录入口等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

本文实例讲述了python操作gmail的方法。分享给大家供大家参考。

具体实现方法如下:

 
class pygmail(object):
    def __init__(self):
        self.IMAP_SERVER='imap.gmail.com'
        self.IMAP_PORT=993
        self.M = None
        self.response = None
        self.mailboxes = []
 
    def login(self, username, password):
        self.M = imaplib.IMAP4_SSL(self.IMAP_SERVER, self.IMAP_PORT)
        rc, self.response = self.M.login(username, password)
        return rc
 
    def get_mailboxes(self):
        rc, self.response = self.M.list()
        for item in self.response:
            self.mailboxes.append(item.split()[-1])
        return rc
 
    def get_mail_count(self, folder='Inbox'):
        rc, self.response = self.M.select(folder)
        return self.response[0]
 
    def get_unread_count(self, folder='Inbox'):
        rc, self.response = self.M.status(folder, "(UNSEEN)")
        unreadCount = re.search("UNSEEN (\d+)", self.response[0]).group(1)
        return unreadCount
 
    def get_imap_quota(self):
        quotaStr = self.M.getquotaroot("Inbox")[1][1][0]
        r = re.compile('\d+').findall(quotaStr)
        if r == []:
            r.append(0)
            r.append(0)
        return float(r[1])/1024, float(r[0])/1024
 
    def get_mails_from(self, uid, folder='Inbox'):
        status, count = self.M.select(folder, readonly=1)
        status, response = self.M.search(None, 'FROM', uid)
        email_ids = [e_id for e_id in response[0].split()]
        return email_ids
 
    def get_mail_from_id(self, id):
        status, response = self.M.fetch(id, '(body[header.fields (subject)])')
        return response
 
    def rename_mailbox(self, oldmailbox, newmailbox):
        rc, self.response = self.M.rename(oldmailbox, newmailbox)
        return rc
 
    def create_mailbox(self, mailbox):
        rc, self.response = self.M.create(mailbox)
        return rc
 
    def delete_mailbox(self, mailbox):
        rc, self.response = self.M.delete(mailbox)
        return rc
 
    def logout(self):
        self.M.logout()
 
if __name__ =="__main__":
    demo=pygmail()
    demo.login("renwenchao888@gmail.com","qqq191430791")
    mailBoxex=demo.get_mailboxes()
    for i in demo.response:
        print i
    demo.logout()</div>

希望本文所述对大家的Python程序设计有所帮助。

</div>

您可能想查找下面的文章:

  • 用Python登录Gmail并发送Gmail邮件的教程
  • python操作gmail实例

相关文章

  • python 生成目录树及显示文件大小的代码
  • 玩转python爬虫之爬取糗事百科段子
  • 简介Python的collections模块中defaultdict类型的用法
  • python获取beautifulphoto随机某图片代码实例
  • 一个基于flask的web应用诞生 用户注册功能开发(5)
  • python设置检查点简单实现代码
  • Python时间的精准正则匹配方法分析
  • Fabric 应用案例
  • 跟老齐学Python之变量和参数
  • Python引用模块和查找模块路径

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • 详细解读Python中解析XML数据的方法
    • python使用post提交数据到远程url的方法
    • python算法表示概念扫盲教程
    • python中遍历文件的3个方法
    • Python获取Windows或Linux主机名称通用函数分享
    • python实现在windows服务中新建进程的方法
    • python模拟新浪微博登陆功能(新浪微博爬虫)
    • Python的__builtin__模块中的一些要点知识
    • Python 爬虫爬取指定博客的所有文章
    • 用Python实现斐波那契(Fibonacci)函数

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有