Chinaunix首页 | 论坛 | 博客
  • 博客访问: 12471
  • 博文数量: 3
  • 博客积分: 241
  • 博客等级: 二等列兵
  • 技术积分: 80
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-21 12:07
文章分类
文章存档

2013年(3)

分类: PERL

2013-03-14 11:39:53

perl SMTP发送邮件



#!/usr/bin/perl
use strict;
use Net::SMTP;
use
Authen::SASL;
        my $data;
        my $NUM=0;
        my
$mail_name;
my $name;
my $mail;
    my $LogFile="message.txt"; 发送邮件内容
:如 我是邮件内容,我和别人不一样的地方 {<--name-->}
my $mail_name_file="list.txt";
发送邮件地址列表和 每封邮件需要替换的内容 如:    我们是要替换的内容
open (FILE,"$LogFile") or die "Can not
open $LogFile for reading : $!";
open (FILE1,"$mail_name_file") or die "Can
not open $LogFile for reading : $!";
my @message=;
my
@mail_name=;


sub sendmail{
my $message;
($name,$mail) =
@_;
$message=join('',@message);
$message =~ s/{<--name-->}/$name/;
#替换发送邮件内容需要替换的内容
# print $message;
print $mail;
my $from =
;
my $to = '$mail';
my $username =
;
my $passwd = '65432111111';
my $subject =
'Test Email';
my $smtp = Net::SMTP->new('mail.woyo.com');


$smtp->auth($username,$passwd) or die "Could not authenticate
$!";
$smtp->mail($from);
$smtp->to($to);


$smtp->data();
$smtp->datasend("From:$from\n");
$smtp->datasend("To:
$to\n");
#$smtp->datasend("Cc: $Cc\n");
$smtp->datasend("Subject:
$subject\n");
$smtp->datasend("This is a test perl email\nIt is
successfull");
$smtp->dataend();


$smtp->quit;



}




foreach $mail_name(@mail_name)
{
my @arr;
@arr =
split(/\s+/,$mail_name);
sendmail($arr[0],$arr[1])
}

阅读(1612) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇: linux 安全关机脚本

给主人留下些什么吧!~~