Perl Requires Chilkat v11.0.0+
Chilkat2 Perl
Find the "Sent" IMAP Mailbox
See more IMAP Examples
Find the "Sent" IMAP mailbox. Also finds the Junk and Trash mailboxes..Chilkat Perl Downloads
use strict;
use warnings;
use Chilkat2;
# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
my $imap = Chilkat2::Imap->new;
$imap->Ssl(1);
$imap->Port(993);
my $success = $imap->Connect('imap.yourmailserver.com');
if (!$success) {
print $imap->LastErrorText, "\n";
exit;
}
# Login or authenticate in some way..
$success = $imap->Login('your_login', 'your_password');
if (!$success) {
print $imap->LastErrorText, "\n";
exit;
}
# Get the list of mailboxes.
my $refName = '';
my $wildcardedMailbox = '*';
my $subscribed = 0;
my $mboxes = Chilkat2::Mailboxes->new;
$success = $imap->MbxList($subscribed, $refName, $wildcardedMailbox, $mboxes);
if (!$success) {
print $imap->LastErrorText, "\n";
exit;
}
# The mailbox with the "/Sent" flag is the "Sent" mailbox.
# Likewise for Junk and Trash..
my $i = 0;
while ($i < $mboxes->Count) {
if ($mboxes->HasFlag($i, '\Sent')) {
print 'Sent mailbox: ', $mboxes->GetName($i), "\n";
}
if ($mboxes->HasFlag($i, '\Junk')) {
print 'Junk mailbox: ', $mboxes->GetName($i), "\n";
}
if ($mboxes->HasFlag($i, '\Trash')) {
print 'Trash mailbox: ', $mboxes->GetName($i), "\n";
}
$i = $i + 1;
}
# Disconnect from the IMAP server.
$success = $imap->Disconnect();