Retrieve Email Attachments

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Fazer

    Retrieve Email Attachments

    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.
  • Lutz Horn

    #2
    Re: Retrieve Email Attachments

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

    Use poplib or imaplib to get a message as a string.
    [color=blue][color=green][color=darkred]
    >>> import poplib
    >>> connection = poplib.POP3("se rvername")
    >>> connection.user ("username")
    >>> connection.pass _("password")[/color][/color][/color]

    Then use the email module (new in 2.2) to parse this string into an
    instance of email.Messsage using
    [color=blue][color=green][color=darkred]
    >>> import email
    >>> msg = email.message_f rom_string(msg_ as_string)[/color][/color][/color]

    Use the methods of the resulting email.Message instance to get the
    contents of the email.

    Lutz

    Comment

    • Lutz Horn

      #3
      Re: Retrieve Email Attachments

      Lutz Horn wrote:[color=blue]
      > Use poplib or imaplib to get a message as a string.
      >[color=green][color=darkred]
      > >>> import poplib
      > >>> connection = poplib.POP3("se rvername")
      > >>> connection.user ("username")
      > >>> connection.pass _("password")[/color][/color][/color]

      forgot:
      [color=blue][color=green][color=darkred]
      >>> msg_as_string = connection.get( number_of_messa ge_on_server)[/color][/color][/color]
      [color=blue]
      > Then use the email module (new in 2.2) to parse this string into an
      > instance of email.Messsage using
      >[color=green][color=darkred]
      > >>> import email
      > >>> msg = email.message_f rom_string(msg_ as_string)[/color][/color]
      >
      > Use the methods of the resulting email.Message instance to get the
      > contents of the email.[/color]

      Comment

      • deelan

        #4
        Re: Retrieve Email Attachments

        Fazer wrote:
        [color=blue]
        > 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?[/color]
        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/> .

        Comment

        • Fazer

          #5
          Re: Retrieve Email Attachments

          Thanks a lot for your guide!

          Lutz Horn <lho@gmx.de> wrote in message news:<2gj7b8F3f d4cU2@uni-berlin.de>...[color=blue]
          > Lutz Horn wrote:[color=green]
          > > Use poplib or imaplib to get a message as a string.
          > >[color=darkred]
          > > >>> import poplib
          > > >>> connection = poplib.POP3("se rvername")
          > > >>> connection.user ("username")
          > > >>> connection.pass _("password")[/color][/color]
          >
          > forgot:
          >[color=green][color=darkred]
          > >>> msg_as_string = connection.get( number_of_messa ge_on_server)[/color][/color]
          >[color=green]
          > > Then use the email module (new in 2.2) to parse this string into an
          > > instance of email.Messsage using
          > >[color=darkred]
          > > >>> import email
          > > >>> msg = email.message_f rom_string(msg_ as_string)[/color]
          > >
          > > Use the methods of the resulting email.Message instance to get the
          > > contents of the email.[/color][/color]

          Comment

          • Fazer

            #6
            Re: Retrieve Email Attachments

            Wow! Exactly what I needed. Thanks a million!

            deelan <ggg@zzz.it> wrote in message news:<62328c.l5 b.ln@news1.inte rplanet.it>...[color=blue]
            > Fazer wrote:
            >[color=green]
            > > 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?[/color]
            > i've posted an example script non too long ago:
            > <http://tinyurl.com/yuhmn>
            >
            > cheers,
            > deelan[/color]

            Comment

            Working...