Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

How to Fetch Gmail

by lalitbans (Novice)
on Jan 18, 2011 at 12:15 UTC ( #882857=perlquestion: print w/replies, xml ) Need Help??

lalitbans has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, I put this code in my script and i got html of my inbox. I got From, Subject, Mailurl, Date etc etc but still i am not been able to open the mails content. Please help.

$mech->get( "" ); $mech->content(); $mech->submit_form( form_number => '1', fields => { Email => $username, Passwd => $password, } ); my $inbox_url = ""; $mech->get($inbox_url); $mailbox = $mech->content();

Replies are listed 'Best First'.
Re: How to Fetch Gmail
by lyklev (Pilgrim) on Jan 18, 2011 at 13:28 UTC

    @labels is an array. $labels[0] prints the first element of that array. If that label is empty or an empty string, your program prints nothing.

    Also, as usual,

    use warnings
    is a great help, as it will tell you if you are trying to print something undefined.

Re: How to Fetch Gmail
by ww (Archbishop) on Jan 18, 2011 at 12:47 UTC

    From the doc:

    ### Print out all user defined labels my @labels = $gmail->get_labels(); foreach ( @labels ) { print "Label: '" . $_ . "'\n"; }

    or, more extensively, for get-and-read scenario:

    my $messages = $gmail->get_messages(); print "By folder\n"; foreach ( keys %Mail::Webmail::Gmail::FOLDERS ) { print "KEY: $_\n"; my $messages = $gmail->get_messages( label => $Mail::Webmail:: +Gmail::FOLDERS{ $_ } ); print "\t$_:\n"; if ( @{ $messages } ) { foreach ( @{ $messages } ) { print "\t\t$_->{ 'subject' }\n"; } } } print "By label\n"; foreach ( $gmail->get_labels() ) { $messages = $gmail->get_messages( label => $_ ); print "\t$_:\n"; if ( defined( $messages ) ) { if ( @{ $messages } ) { foreach ( @{ $messages } ) { print "\t\t$_->{ 'subject' }\n"; } } } }

    Looks to me as though you didn't check the doc (perldoc Mail::Webmail::Gmail) -- an especially important trick in developing your knowledge of Perl.

      I'm not sure what the difference between your first example and the OPs is? I've run both, and get 0 labels back, which is the OPs problem. I'm also getting 0 back when I use get_messages()

      What result do you get?

        OP's code is print $label[0] (and no semicolon, tho that's no big deal here)

        As pointed out by lyklev below, $label[0] can be empty.

        Example code, from the doc, suggests foreaching the array.
Re: How to Fetch Gmail
by sweetblood (Prior) on Jan 18, 2011 at 15:39 UTC
    After reviewing the docs for this module as well as reviews and the bug list it would appear this module does not work and has not worked in sometime. The description listed in the documentation reads as follows.


    Because Gmail is currently in Beta testing, expect this module to break as they make updates to thier interface. I will attempt to keep this module in line with the changes they make, but, if after updating to the newest version of this module, the feature that you require still doesn't work, please contact me with the issue.

    Given that the module is close to 5 years old and gmail has undergone many updates it seems unlikely that this would work. You would probably have more success using pop3 or imap. Good Luck


      Thanks for everyone who reply for the very same. It is so beneficial for me.. Now i am going to use Mail::IMAPClient module for fetch Email from Gmail.

        Yes, IMAP is definetely the way to go. Mail::IMAPTalk is a very good IMAP client. You might also be interested in lookin at Gmail's IMAP behavior chart.


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://882857]
Approved by Corion
Front-paged by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2022-10-01 02:45 GMT
Find Nodes?
    Voting Booth?
    I prefer my indexes to start at:

    Results (126 votes). Check out past polls.