Retrieve Email Attachments

Lutz Horn lho at gmx.de
Fri May 14 02:29:32 EDT 2004


Lutz Horn wrote:
> Use poplib or imaplib to get a message as a string.
> 
>  >>> import poplib
>  >>> connection = poplib.POP3("servername")
>  >>> connection.user("username")
>  >>> connection.pass_("password")

forgot:

 >>> msg_as_string = connection.get(number_of_message_on_server)

> Then use the email module (new in 2.2) to parse this string into an 
> instance of email.Messsage using
> 
>  >>> import email
>  >>> msg = email.message_from_string(msg_as_string)
> 
> Use the methods of the resulting email.Message instance to get the 
> contents of the email.



More information about the Python-list mailing list