By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,986 Members | 1,568 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,986 IT Pros & Developers. It's quick & easy.

Retrieve Email Attachments

P: n/a
Hello,

I need to access a POP or mayb IMAP based email account and extract
attachments (probably images) from the email messages. How can this
be done with the current two module libraries?

Thanks for any insight.

Faizan.
Jul 18 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
> I need to access a POP or mayb IMAP based email account and extract
attachments (probably images) from the email messages. How can this
be done with the current two module libraries?


Use poplib or imaplib to get a message as a string.
import poplib
connection = poplib.POP3("servername")
connection.user("username")
connection.pass_("password")
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.

Lutz
Jul 18 '05 #2

P: n/a
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.

Jul 18 '05 #3

P: n/a
Fazer wrote:
Hello,

I need to access a POP or mayb IMAP based email account and extract
attachments (probably images) from the email messages. How can this
be done with the current two module libraries?

i've posted an example script non too long ago:
<http://tinyurl.com/yuhmn>

cheers,
deelan

--
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
<#me> a foaf:Person ; foaf:nick "deelan" ;
foaf:weblog <http://www.deelan.com/> .
Jul 18 '05 #4

P: n/a
Thanks a lot for your guide!

Lutz Horn <lh*@gmx.de> wrote in message news:<2g************@uni-berlin.de>...
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.

Jul 18 '05 #5

P: n/a
Wow! Exactly what I needed. Thanks a million!

deelan <gg*@zzz.it> wrote in message news:<62***********@news1.interplanet.it>...
Fazer wrote:
Hello,

I need to access a POP or mayb IMAP based email account and extract
attachments (probably images) from the email messages. How can this
be done with the current two module libraries?

i've posted an example script non too long ago:
<http://tinyurl.com/yuhmn>

cheers,
deelan

Jul 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.