1

I want to download my emails via IMAP from email account and upload them to another. I want to do that manually in Python. I know how to retrieve my emails via IMAP, but how can I actually "upload" them to my another email account? Is there a standard way or does that depend on my 2nd email server?

2
  • Is this just an exercise, and if not, why do you want to use python and not imapsync?
    – Law29
    Commented Apr 25, 2016 at 4:45
  • @Law29, because.
    – Oskar K.
    Commented Apr 25, 2016 at 9:20

1 Answer 1

1

You can upload with python as well:

import imaplib

# an alternative for IMAP4_SSL is IMAP4 if you're doing this locally
imap = imaplib.IMAP4_SSL(your_2nd_server, its_imap_portnumber)  
imap.login(user_name, password)

and then for each message you downloaded:

imap.append(mailbox, [], delivery_time, message)

You have to get the delivery time out of the message header for this.

10
  • does imap allow me to upload an email? is that by specification?
    – Oskar K.
    Commented Apr 25, 2016 at 9:21
  • @OskarK. Sure it is APPEND, that is how you can e.g. move an email from one (IMAP) account in Firefox to another.
    – Anthon
    Commented Apr 25, 2016 at 9:22
  • @OskarK. do note that "uploading" an email only means that you put it in the box, not that you send it to anyone, for that it's (still) SMTP.
    – Law29
    Commented Apr 25, 2016 at 17:19
  • @Law29 That is in principle correct, although there are extensions for IMAP so you don't have to use SMTP and upload the same email to your send-items box if your IMAP server and SMTP server are on the same (remote) machine.
    – Anthon
    Commented Apr 25, 2016 at 17:21
  • 1
    @Law29 The IETF LEMONADE Working Group has made some RFCs for that (4467-4468-4469) I don't know of any servers actually implementing them.
    – Anthon
    Commented Apr 25, 2016 at 17:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .