IMAP: how to move a message from one folder to another

前端 未结 4 437
故里飘歌
故里飘歌 2020-12-28 16:44

(using the IMAP commands, not with the assistance of any other mail package)

4条回答
  •  长情又很酷
    2020-12-28 17:21

    If you have the uid of the email which is going to be moved.

    import imaplib
    
    obj = imaplib.IMAP4_SSL('imap.gmail.com', 993)
    obj.login('username', 'password')
    obj.select(src_folder_name)
    apply_lbl_msg = obj.uid('COPY', msg_uid, desti_folder_name)
    if apply_lbl_msg[0] == 'OK':
        mov, data = obj.uid('STORE', msg_uid , '+FLAGS', '(\Deleted)')
        obj.expunge()
    

    Where msg_uid is the uid of the mail.

提交回复
热议问题