0

How do I move emails into folders using the IMAP library in python?

Trying to move an email from one folder into another. I have the uid of the emails that I want to move.

  • Quick pointers: check `CAPABILITIES` for move, if available, use `conn.uid('move', ). If not, use uid('copy', ...), uid('store', uid '\Deleted'), and uid('expunge', uid) – Max Jun 03 '20 at 16:14

1 Answers1

0
from imap_tools import MailBox, A
with MailBox('imap.mail.ru').login('test@ya.ya', 'pw', initial_folder='INBOX') as mailbox:
    # MOVE all messages from current folder (INBOX) to folder2
    mailbox.move(mailbox.uids(A(all=True)), 'INBOX/folder2')

Lib: https://github.com/ikvk/imap_tools

Vladimir
  • 6,162
  • 2
  • 32
  • 36