imap-如何删除邮件 [英] imap - how to delete messages

查看:748
本文介绍了imap-如何删除邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从邮箱中删除邮件?我正在使用此代码,但字母不会被删除.对不起,我的英语.

How can I delete messages from the mail box? I am using this code, but the letters are not removed. Sorry for my English.

def getimap(self,server,port,login,password):
    import imaplib, email
    box = imaplib.IMAP4(server,port)
    box.login(login,password)
    box.select()
    box.expunge()
    typ, data = box.search(None, 'ALL')
    for num in data[0].split() :
        typ, data = box.fetch(num, '(UID BODY[TEXT])')
        print num
        print data[0][1]
    box.close()
    box.logout()

推荐答案

这是删除收件箱中所有电子邮件的有效代码:

This is the working code for deleting all emails in your inbox:

import imaplib
box = imaplib.IMAP4_SSL('imap.mail.microsoftonline.com', 993)
box.login("user@domain.com","paswword")
box.select('Inbox')
typ, data = box.search(None, 'ALL')
for num in data[0].split():
   box.store(num, '+FLAGS', '\\Deleted')
box.expunge()
box.close()
box.logout()

这篇关于imap-如何删除邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆