На коленке перлокод:
use Net::SMTP::TLS;
my $mailer = new Net::SMTP::TLS(
'smtp.gmail.com',
Hello => 'smtp.gmail.com',
Port => 587,
User => $USERNAME,
Password=> $PASSWORD);
$mailer->mail($FROM);
$mailer->to($to);
$mailer->data;
$mailer->datasend("From: $FROM\r\n");
$mailer->datasend("To: $to\r\n");
$mailer->datasend("Subject: Hello my friend\r\n");
$mailer->datasend("List-Unsubscribe: unsubscribe@domain.com\r\n");
$mailer->datasend("Content-Type: text/plain; charset=utf-8\r\n");
$mailer->datasend("\r\n");
$mailer->datasend("Hello, $name! How are you?");
$mailer->dataend;
$mailer->quit;
Ну в цикле вызываете…