#!/usr/bin/perl -w
use strict;
use Net::SMTP;
use Authen::SASL;(在SMTP伺服器上要求使用者認證,必須的模組)
BEGIN {
push (@INC,'/usr/lib/perl5/5.8.8/Net/ ');
}
my $from = 'huashan125@huashan.peonymao.com';
my $to = 'peonymao@orrisintl.com';
my $username = 'huashan125';
my $passwd = 'huashan125';
my $subject = 'Test Email';
my $smtp = Net::SMTP->new('192.168.21.82');
$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;
---------------------------------------------------以下是自己寫的例子--------------------------------------
#!/usr/bin/perl -w
use Net::SMTP;
$smtp = Net::SMTP->new('10.1.28.22'); #郵件伺服器地址
$smtp->mail('zhang@163.com'); #寄件者
$smtp->to('zhang@sina.com'); #收件者
$smtp->to('zhang@163.com');
$smtp->data();
$smtp->datasend("From:/"zhang/" <zhang/@163.com>/n");
$smtp->datasend("To: /"zhang/" <zhang/@sina.com>,/n /"zhang/" <zhang/@163.com>,/n" );
$smtp->datasend("Subject: monitor_prov/n/n"); #主題
my $my_url = 'http://127.0.0.1:8081/div.html' . "/n";
#my $my_url = '<a href="http://127.0.0.1:8081/div.html">monitor_info</a><br>' . "/n";
$smtp->datasend($my_url);
$smtp->datasend("test mail/n");
$smtp->dataend();
$smtp->quit;