[code.view]

[top] / python / PyMOTW / imaplib / imaplib_append.py

     #!/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))
         
         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()
     

[top] / python / PyMOTW / imaplib / imaplib_append.py

contact | logmethods.com