Sample code for 30+ languages & platforms
CkPython

Upload (Append) Email to an IMAP Mailbox

Upload / append an email to an IMAP mailbox.

Chilkat CkPython Downloads

CkPython
import sys
import chilkat

success = False

# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.

imap = chilkat.CkImap()

# Connect to an IMAP server.
# Use TLS
imap.put_Ssl(True)
imap.put_Port(993)
success = imap.Connect("imap.example.com")
if (success != True):
    print(imap.lastErrorText())
    sys.exit()

# Login
success = imap.Login("myLogin","myPassword")
if (success != True):
    print(imap.lastErrorText())
    sys.exit()

email = chilkat.CkEmail()

# Load the email from a .eml file.
success = email.LoadEml("myEmail.eml")
if (success != True):
    print(email.lastErrorText())
    sys.exit()

success = imap.AppendMail("Inbox",email)
if (success != True):
    print(imap.lastErrorText())
    sys.exit()

print("Email uploaded to Inbox!")

# Disconnect from the IMAP server.
success = imap.Disconnect()