如果要把诸如“工作站备份完毕”或者“阿波罗服务器磁盘空间即将耗尽”这样的简单消息发送给任何带有电子邮件地址的文本消息设备,例如移动电话或者文字传呼机,就要使用下面的脚本:
useNet::SMTP;
$SMTPSERVER = ''; #
set to your SMTP mail server
die qq!Usage: FROM TO "SUBJECT" "CONTENT"
! if (scalar(@ARGV)
!= 4);
SendMail(@ARGV);
sub SendMail
{
my ($from, $to, $subject, $content) = @_;
my $smtp = Net::SMTP->new($SMTPSERVER);
if ($smtp == undef)
{
print("*
Message not sent: Can't connect to mail host '$SMTPSERVER'!
");
}
else
{
$smtp->mail($from);
$smtp->to($to);
my $result = $smtp->data("From:
$from
To: $to
Subject: $subject
$content
");
$smtp->quit();
print "*
Message not sent: data command failed on remote host $SMTPSERVER
" if
(! $result);
}
}