写了一个perl邮件群发脚本,代码如下:

#!/usr/bin/perl -w
#requirement:
#rpm -ivh http://dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
#yum -y install perl-Authen-SASL perl-MIME-Base64
#
#Author: Luo Hui 2008.12.01
#
use warnings;
use strict;
use MIME::Base64;
use Net::SMTP;

#邮件内容
my mailfile = /root/mail1128.htm;
#邮件列表文件,一行一个邮件地址
my maillist = /root/maillist.txt;
#发送服务器
my smtp_server = mail.test.com;
#认证用户名
my username = mailto:service@test.com;
#认证密码
my password = 111111;
#发件人
my from_mail = mailto:service@test.com;
#邮件主题
my subject = encode_base64( test test,   );

open(FHML, maillist) or die !;
my @to_mails = ;
close( FHML );

open(FHMF, mailfile) or die !;
local(/) = undef;
my mail_body = ;
close( FHMF );
/ = n;

mail_body = encode_base64( mail_body,   );

my smtp = Net::SMTP -> new( Host => smtp_server,
#            Debug => 1,
            Hello => smtp_server,
            ) || die Cant connect smtp_server !n;

smtp -> auth( username, password ) || die Cant authenticate: !n;

my i = 0;
foreach my to_mail( @to_mails )
{
    chomp(to_mail);
    smtp -> mail( from_mail );
    smtp -> to( to_mail );
    smtp -> data( );

    # send mail head
    smtp -> datasend( From: from_mailn );
    smtp -> datasend( To: to_mailn );
    smtp -> datasend( MIME-Version: 1.0 n );
    smtp -> datasend( Content-Type: text/html; charset=gb2312 n );
    smtp -> datasend( Content-Transfer-Encoding: base64n );
    smtp -> datasend( Subject: =?gb2312?B?subject?=nn);
   
    # send mail body
    smtp -> datasend( mail_body );
    smtp -> dataend();

    i++;
    print send mail:i mail to:to_mailn;
}

$smtp -> quit();

运行需要下面perl-Authen-SASL perl-MIME-Base64两个库,用下面命令安装:

rpm -ivh http://dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
yum -y install perl-Authen-SASL perl-MIME-Base64