mail processing module?
Preston Landers
prestonlanders at my-deja.com
Tue Dec 26 13:48:49 EST 2000
In article <91vumo$di3$1 at nnrp1.deja.com>,
Preston Landers <prestonlanders at my-deja.com> wrote:
I just want to see if people have had a chance to glance at this, the
current interface to the maillib draft and tell me a good reason why
it's horribly broken, or need some tweaking, or is just fine. I've
gotten tenative permission to post code, but I need to sort out a few
more details. I want to see if I can get some preliminary feedback on
the module interface. I will be making some tweaks to make it fully
agnostic of transport mechanisms, but my basic plan is still to unify
all the lower level modules into one maillib module (with several
internal helper classes...)
thanks
Preston
> Like I said, I am trying to:
>
> a) reimplement as little as possible
>
> b) make the interface for using the module as simple as possible
>
> Here's an example of use (sorry if there are formatting problems):
>
> import maillib
>
> # make mail exception availible in this namespace
> MailError = maillib.MailError
>
> # set up a configuration dictionary with the recommended options
>
> config_dict = {
>
> 'sendmail_from': 'Your Name <your at address.here>',
> 'sendmail_smtphost': 'smtp.yourdomain.com',
> 'sendmail_user_agent': 'Catchy Slogan Here',
>
> 'getmail_method': 'imap', # or 'pop'
> 'getmail_user': 'uname',
> 'getmail_passwd': 'pwd',
> 'getmail_server': 'imap-server.yourdomain.com',
> 'getmail_server_port': 143, # standard imap port, 110 is POP port
>
> }
>
> Debug = None # set to 1 for more verbose output to stderr
> my_mail = maillib.maillib(config_dict, Debug) # you now have a
maillib
> object
>
> ### SENDING MAIL
>
> mailto_list = ['destination at address.com']
> subject = 'Hello, maillib!'
> mail_body = 'Hello, world.'
>
> attachment_list = [] # no attachments, empty list or None
>
> ### ATTACHMENT 1
>
> description_1 = 'Picture of Tux the Penguin'
> filename_1 = 'tux.jpg'
> mimetype_1 = None # let the module guess from the filename, only
works
> with common types
> item_1 = open_file_handle.read()
> attachment_1 = (description_1, mimetype_1, filename_1, item_1)
>
> attachment_list.append(attachment_1)
>
> try:
> my_mail.send_mail(mailto_list, subject, mail_body,
attachment_list)
> except MailError, msg:
> print 'There was a mail sending problem'
> print msg
> raise
>
> print 'Mail sent ok.'
>
> # RECIEVE EMAIL
>
> try:
> my_mail.getmail_login()
> Delete = 1 # delete the message after you fetch it
> raw_message = my_mail.fetch_first_msg(Delete)
> my_mail.do_cleanup() # logs off mail server!
> except MailError, msg:
> print 'There was a problem retrieving the email.'
> print msg
>
> ### The raw unprocessed message is now in raw_message
>
> ### DECODING MESSAGES
>
> try:
> (header_dict, message_body, attachments_list) =
> my_mail.decode_email(raw_message)
> except MailError, msg:
> print 'There was a problem decoding the email.'
> print msg
>
> print 'From: ', header_dict.get('From', 'unknown')
> print 'To: ', header_dict.get('To', 'unknown')
> print
> print message_body
>
> --- Preston <pibble at yahoo dot com>
>
> Sent via Deja.com
> http://www.deja.com/
>
--
|| Preston Landers <prestonlanders at my-deja.com> ||
Sent via Deja.com
http://www.deja.com/
More information about the Python-list
mailing list