perl 发送mail

前端之家收集整理的这篇文章主要介绍了perl 发送mail前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1,需要的两个主要的lib

http://search.cpan.org/~shay/libnet-1.27/Net/SMTP.pm

http://search.cpan.org/~gbarr/Authen-SASL-2.16/lib/Authen/SASL.pod


2,使用perl发送mail

#!/usr/bin/perl
use strict;
use warnings;
use Net::SMTP;
use Authen::SASL;


my $mailhost = 'smtp.qq.com';
my $mailfrom = 'mailfromxxx@qq.com';
my $mailto   = 'mailtoxxx@qq.com';
my $subject  = 'subject';
my $content  = 'content';

my $smtp = Net::SMTP->new('smtp.qq.com',Timeout => 30
                           );
$smtp->auth('username@qq.com','password');

$smtp->mail($mailfrom);
$smtp->to($mailto);
$smtp->data();
$smtp->datasend("To: recipient\n");
$smtp->datasend("\n");
$smtp->datasend("Line1\nLine2\n");
$smtp->dataend();

$smtp->quit;


3,操作结果



参考:

http://bbs.chinaunix.net/thread-1499038-1-1.html

猜你在找的Perl相关文章