imap - 如何删除消息
如何删除邮箱中的邮件?我正在使用这个代码,但字母没有被删除。对不起我的英语。
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()
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()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
这是删除收件箱中所有电子邮件的工作代码:
This is the working code for deleting all emails in your inbox:
我认为你应该首先标记要删除的电子邮件..例如:
I think you should mark the emails to be deleted, first.. For example:
这对我有用,而且速度非常快,因为我不会单独删除(存储)每封电子邮件,而是传递列表索引。这适用于个人 Gmail 和企业 Gmail(Google Apps for Business)。它首先选择要使用的文件夹/标签 m.list() 将显示所有可用的。然后,它会搜索一年以上的电子邮件,并移至垃圾箱。然后它用删除标志标记垃圾箱中的所有电子邮件并删除所有内容:
This is what works for me, and it is really fast as I don't delete each email individually (store) but pass the list index instead. This works for gmail personal as well as enterprise (Google Apps for Business). It first selects the folder/label to use m.list() will show you all available. It then searches for emails over a year old, and performs a move to trash. It then flags all the emails in trash with the delete flag and expunges everything:
以下代码打印一些消息头字段,然后删除消息。
The following code prints some message header fields and then delete message.
如果您使用的是 GMail,则过程会有所不同:
[Gmail]/Spam 和 [Gmail]/Trash 中的所有电子邮件将在 30 天后删除。
如果您从[Gmail]/垃圾邮件或[Gmail]/垃圾箱中删除邮件,该邮件将被永久删除。
还记得在设置标签“已删除”后调用EXPUNGE。
If you are using GMail the process is a bit different:
All emails in [Gmail]/Spam and [Gmail]/Trash are deleted after 30 days.
If you delete a message from [Gmail]/Spam or [Gmail]/Trash, it will be deleted permanently.
Remember also to call EXPUNGE after setting the tag Deleted.
这是我根据上面的代码编写的程序:
https://github.com/ AndrewDJohnson/py-purge-email/
Here is a program I wrote, based on the code above:
https://github.com/AndrewDJohnson/py-purge-email/
从收件箱中删除所有电子邮件。
删除所有带有日期条件的电子邮件。
此程序将删除自当前日期起 20 天之前的所有电子邮件。
调整程序中变量 Dy 中的天数。例子。 DY = 20
Delete all emails from inbox.
Delete all emails with date condition.
This program will delete all emails older that 20 days from the current date.
Adjust the days in variable Dy in program. example. DY = 20
这是我用来删除或保留 Outlook 收件箱文件夹中的电子邮件的流程工作流程。
管理电子邮件是一个持续的维护问题。
有时我有数千封电子邮件需要删除。
我创建了两个 python 程序,这将使我能够有效地管理这个流程工作流程。
首先 - 我编写一个 python 程序来创建文本和 CSV 文件。
文本和 CSV 文件包含两部分。
其次 - 我编辑文本或 CSV 文件以创建两个文本文件。
A. 我想保留且无删除条件的电子邮件。
B. 我将手动管理这些电子邮件。
A. 我想根据变量 EndDy 的日期值保留或删除电子邮件。
我将根据需要附加这两个文本文件。
第三 - 我编写了第二个 python 程序来根据四个条件删除或保留电子邮件。
删除没有电子邮件地址的电子邮件。
保留 EmailsToKeep.txt 文本文件中的电子邮件。
保留或删除 EmailsToKeepForAtLeast30Days.txt 文本文件中的电子邮件。
A. 如果日期比变量 EndDy 的日期值新,则保留电子邮件。
B. 如果日期早于变量 EndDy 的日期值,则删除电子邮件。
删除未包含在任何 EmailsToKeep.txt 或 EmailsToKeepForAtLeast30Days.txt 文本文件中的电子邮件。
视频链接:https://youtu.be/bTgb3tO5r-8
This is the process workflow I use to either delete or keep emails in Outlook Inbox folder.
Managing emails is a constant maintenance issue.
Sometimes I have thousands of emails that I need to delete.
I have created two python programs which will enable me to efficiently manage this process workflow.
First - I write a python program to create a text and CSV file.
The text and CSV file contains two parts.
Second - I edit the text or CSV file to create two text files.
A. Emails I want to keep with no delete condition.
B. I will manage these emails manually.
A. Emails I want to keep or delete base on the date value of variable EndDy.
I will append these two text files as needed.
Third - I write a second python program to delete or keep emails based on four conditions.
Delete emails that have no email address.
Keep emails that are in the EmailsToKeep.txt text file.
Keep or delete emails that are in the EmailsToKeepForAtLeast30Days.txt text file.
A. Keep emails if date is newer than the date value of variable EndDy.
B. Delete emails if date is older than the date value of variable EndDy.
Delete emails that were not included in any of the EmailsToKeep.txt or EmailsToKeepForAtLeast30Days.txt text files.
Video link: https://youtu.be/bTgb3tO5r-8
尝试使用 https://github.com/ikvk/imap_tools
Try to use https://github.com/ikvk/imap_tools