perl利用SMTP發送郵件指令碼(帶認證)

來源:互聯網
上載者:User

#!/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;

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.