Search code examples
djangogmailimap

Revert emails fetched via django-mailbox, back to Gmail inbox


I am a Django newbie. I have setup a mailbox in Django admin using the django-mailbox package. The URI configuration was a Gmail IMAP email server. While retrieving mails into my Django mailbox, they got deleted from the inbox and got created as db records. Is there a way to revert the emails back to the Gmail inbox, either using a Django API, gsuite's email recovery, or exporting data from db into Gmail inbox?

Thanks in advance for your help. P.S. the mails are not present in the trash folder.


Solution

  • You might try iterating over each django_mailbox.Message instance, use the get_email_object method to help generate a MIME message, then use IMAP APPEND to put the message back in your online mailbox.