Created
April 11, 2015 12:56
-
-
Save Averroes/96823c0ea84079919cdd to your computer and use it in GitHub Desktop.
imaplib append
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
# | |
# Copyright (c) 2008 Doug Hellmann All rights reserved. | |
# | |
""" | |
""" | |
__version__ = "$Id$" | |
#end_pymotw_header | |
import imaplib | |
import time | |
import email.message | |
import imaplib_connect | |
new_message = email.message.Message() | |
new_message.set_unixfrom('pymotw') | |
new_message['Subject'] = 'subject goes here' | |
new_message['From'] = 'pymotw@example.com' | |
new_message['To'] = 'example@example.com' | |
new_message.set_payload('This is the body of the message.\n') | |
print new_message | |
c = imaplib_connect.open_connection() | |
try: | |
c.append('INBOX', '', | |
imaplib.Time2Internaldate(time.time()), | |
str(new_message)) | |
# Show the headers for all messages in the mailbox | |
c.select('INBOX') | |
typ, [msg_ids] = c.search(None, 'ALL') | |
for num in msg_ids.split(): | |
typ, msg_data = c.fetch(num, '(BODY.PEEK[HEADER])') | |
for response_part in msg_data: | |
if isinstance(response_part, tuple): | |
print '\n%s:' % num | |
print response_part[1] | |
finally: | |
try: | |
c.close() | |
except: | |
pass | |
c.logout() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment