Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3323978
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:22:00+00:00 2026-05-17T23:22:00+00:00

I am in the process of working on a perl script that will connect

  • 0

I am in the process of working on a perl script that will connect to Gmail and download all the emails. Do keep in mind that I’m only concentrating on connecting to Gmail at the moment, so the script is only set up to cycle through some folders for now. This is what I have so far:

    #!/usr/bin/perl

use strict;
use warnings;
use Mail::IMAPClient;
use IO::Socket::SSL;

# Connect to IMAP via SSL and get rid of greeting message

my $socket = IO::Socket::SSL->new(
 PeerAddr  =>  'imap.gmail.com',
 PeerPort  => 993,
 )
 or die "Socket(): $@";

my $greeting = <$socket>;
my ($id, $answer) = split /\s+/, $greeting;
die "Problems loggin in: $greeting" if $answer ne 'OK';

# Build a client attached to the SSL Socket and login

my $client = Mail::IMAPClient->new(
 Socket => $socket,
 User => 'mail@gmail.com',
 Password => 'password',
 Port  => 993,
 )
 or die "new(): $@";

my ($code, $output) = ("","");
until( $code ) {
 $output = $client->_read_line or return undef;
 for my $o (@$output) {
  $client->_debug("Connect: Recieved this from readline: ".join("/",@$o)."\n");
  $client->_reord($client->Count,$o);
  next unless $o->[Mail::IMAPClient::TYPE] eq "OUTPU";
  ($code) = $o->[Mail::IMAPClient::DATA] =~ /^\*\s+(OK|BAD|NO)/i ;
 }
}

if($code =~ /BYE|NO /) {
 $client->State("Unconnected");
 die "IMAP server disconnected";
}

$client->login;

print "1";

$client->select('INBOX');
my @mails = ($client->seen(),$client->unseen);
foreach my $id (@mails) { print "$id\n"; }
# Terminate the connection with IMAP

$client->logout();

When I run the script, however, the program only sits with a blinking cursor for a long period of time. It returns absolutely no output or errors. Anyone have any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:22:01+00:00Added an answer on May 17, 2026 at 11:22 pm

    It might be easier to use a module that does the IMAP with SSL for you.
    I have used both Net::IMAP::Simple::SSL and Mail::Cclient to connect to IMAP servers over SSL, although I haven’t tried to connect to Gmail.

    Also, I haven’t used Mail::IMAPClient, which you are using, but it does appear to support SSL, and mentions Gmail several times in the documentation, so it should work without having to create your own SSL sockets.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a script that will process user uploads to the server,
I'm writing a perl script that mimics gcc. This my script needs to process
Currently, I'm in the process of hiring a web developer who will be working
I am working on a Perl script to read CSV file and do some
I wrote a perl script using Tie::Handle::CSV to process a bunch of data in
I'm working on a project that calls a console window to process some data
I got very far in a script I am working on only to find
I'm working on a script that currently has: my @files = `$some_command`; print @files;
I am working on a Perl script where it checks for root access, at
I'm writing a Perl program that will take a few command-line arguments (they'll actually

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.