Oct 22, 2008

perl通过gmail发邮件


 


$subject = "中秋快乐";

open(MLIST,"mail.lst");

$j = 0;
while($bcc = <MLIST>){
    $j = $j +1;
    if($j <435){
        next;
    }
    print $bcc;
$mail =<< "MAIL";
Content-Type: text/html; charset=GB2312
Subject:$subject
Bcc:$bcc

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=GB2312" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">

<br>
<br>
</body>
</html>

MAIL
   
    my $id_start = 0;
    my $id = int($j/22)+$id_start;
   
    #total 28 accounts now
    $id = $id %28;
   
    #if(){
       
    #}
    open(FH,">mail/mail_$id_$j.txt");
    print FH $mail;
    close(FH);

    print "$start -- $end -- $j -- $id\n";
    my $cmd = "msmtp  -C msmtprc.txt -t --account=idea_$id --keepbcc=off idea.ma2008\@gmail.com<mail/mail_$id_$j.txt";
    #print "$cmd\n";
    #system $cmd
   
    #try until command success.
    my $sat = system $cmd;
    my $err = 0;
    while($sat){
        #if EX_UNAVAILABLE, try next account
        $err++;
        $cmd = "msmtp  -C msmtprc.txt -t --account=idea_$id --keepbcc=off idea.ma2008\@gmail.com<mail/mail_$id_$j.txt";
        print "[$err][$sat] try again\n ";
        $sat = system $cmd;
        #failure times greater then 6 then exit.
        if($err >= 6){
            exit 1;
        }

    }


--
Thanks
Xiangzhen

No comments:

Post a Comment