Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Parsing Subject and Body Of E-Mail Message

by ProgramIT (Novice)
on Dec 11, 2009 at 21:35 UTC ( #812446=perlquestion: print w/replies, xml ) Need Help??
ProgramIT has asked for the wisdom of the Perl Monks concerning the following question:

I am connecting to an imap server over ssl using Net::IMAP::Simple::SSL. After I connect to the server I download all messages and store them in files. Once the Message has been received I want to store the subject and the body of the message in variables. How Can I do this? I was looking at Email::Abstract and Mail::Internet but I couldn't figure out how to use these packages with the IMAP Package I am currently using. How is the best way to acomplish this?
  • Comment on Parsing Subject and Body Of E-Mail Message

Replies are listed 'Best First'.
Re: Parsing Subject and Body Of E-Mail Message
by GrandFather (Sage) on Dec 11, 2009 at 23:23 UTC
Re: Parsing Subject and Body Of E-Mail Message
by afoken (Abbot) on Dec 11, 2009 at 22:06 UTC



    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re: Parsing Subject and Body Of E-Mail Message
by zwon (Abbot) on Dec 11, 2009 at 22:59 UTC
      Can you explain how to read the body. I have managed to read the headers, but can't find out how to read the body. Here's What I currently have
      #!/usr/bin/perl use strict; use warnings; use Net::IMAP::Simple::SSL; use Email::Simple; # Create the object my $imap = Net::IMAP::Simple::SSL->new('') || die "Unable to connect to IMAP: $Net::IMAP::Simple::errstr\n"; # Log on if(!$imap->login('USER','PASSWORD')){ print STDERR "Login failed: " . $imap->errstr . "\n"; exit(64); } # Print the subject's of all the messages in the INBOX my $nm = $imap->select('INBOX'); for(my $i = 1; $i <= $nm; $i++){ if($imap->seen($i)){ print "*"; } else { print " "; } my $es = Email::Simple->new(join '', @{ $imap->top($i) } ); #print $es->as_string; printf("[%03d] %s\n", $i, $es->header('Subject') . " " . $es-> +header('from')); print $es->body; } $imap->quit;

        I know this is an old post, however I came across it when trying to figure this out myself.

        For others stuck with this example, you will need to change the following line from:

         my $es = Email::Simple->new(join '', @{ $imap->top($i) } );


        my $es = Email::Simple->new( join '', @{ $imap->get($i) } );

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://812446]
Approved by broomduster
[Your Mother]: It would hillarious to learn the Flat Earth movement was started by misunderstood sarcasm.
[Corion]: Your Mother: Aah - Server Side Events maybe, which mostly sends events from the server as they come up?
[Your Mother]: Sounds right.
[Corion]: Your Mother: I think that that is basically the origin story. Flat earth started as trolling, but then the real believers drove out the trolls
LanX is pretty brown in summer
[Your Mother]: Though a bad match for the OP in question here. :P
[Corion]: Your Mother: Yeah
[Your Mother]: Americans are still pumping out video games where you get to slaughter as many Germans as you have the GPU for... It has always struck me as odd that this particular case seems fine to people. :\
[LanX]: yep heard the same origin story

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (17)
As of 2018-03-19 13:37 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (240 votes). Check out past polls.