I'm trying to make a mail bulk downloader with perl, that will connect on multiple accounts and download it´s attachments, but i´m still learning this language. I´m having an issue with credentials stored in a text file reading. Whenever i pass the parameters as string, i can connect to my account and retrieve information about unread emails. Snippet:
my $imap = Mail::IMAPClient->new(
Server => 'mail.example.com',
User => 'nicolas',
Password => 'password',
Uid => 1,
) or die "Erro ao conectar na conta";
It connects, and using my @mails = ($imap->unseen);
with a foreach
loop i can get all my unseen mails on a list.
However, if i try to get my credentials from a file and assign to a variable and further use this variable as credentials to $imap
it fails:
foreach my $line ( @lines ) {
my @credentials = split( /\s+/, $line );
my $domain = $credentials[0];
my $account = $credentials[1];
my $password = $credentials[2];
my $imap = Mail::IMAPClient->new(
Server => 'mail.example.com',
User => $account,
Password => $password,
Uid => 1,)
}
When i run the script i get this message:
$ ./folder_list.pl
Can't call method "select" on an undefined value at ./folder_list.pl line 43.
If i print "$account", "$password";
i can check its values, but cant use them as parameters of $imap
. What am i missing here?