有时候我们在部署脚本的时候,我们想知道,我们的程序执行的怎么样了,想得到执行的结果,这样我们也能放心很多是吧,那么在程序执行成功或失败的时候能够给我没发个邮件很是很不错的。
其实利用perl发邮件的方法有很多种,包括你在cpan上搜索mail关键字是一大堆,经过实践,MIME::Lite用来发邮件还是很合适的,最不可思议的是它可以帮你轻松的发送带有附件的邮件哦。
#!/usr/bin/perl -w
use MIME::Lite;
my $msg = MIME::Lite->new(
From => ‘chenqing663@163.com',
To => ‘chenqing663@foxmail.com',
Cc => ‘some@other.com, some@more.com',
Subject => ‘hello,my first mail from chenqing.org',
Type => ‘multipart/mixed',
Data =>' other data'
);
$msg->attach(
Type => ‘image/png',
Disposition => ‘attachment',
Filename => ‘other.png',
Path => ‘/home/king/perl/logo.png'
);
$msg->send;
#!/usr/bin/perl -w
use MIME::Lite;
my $msg = MIME::Lite->new(
From => ‘chenqing663@163.com',
To => ‘chenqing663@foxmail.com',
Cc => ‘some@other.com, some@more.com',
Subject => ‘hello,my first mail from chenqing.org',
Type => ‘multipart/mixed',
Data =>' other data'
);
$msg->attach(
Type => ‘text/html',
Data => qq{
body>
这是我的 b>good/b> image:
img src=”cid:logo.png”>
/body>
},
);
$msg->attach(
Type => ‘image/png',
Disposition => ‘attachment',
Filename => ‘other.png',
Id => ‘logo.png',
Path => ‘/home/king/perl/logo.png'
);
$msg->send;
#!/usr/bin/perl -w
use MIME::Lite;
use MIME::Base64;
use Authen::SASL;
my $host='smtp.163.com';
my $pass='yourpass';
my $user='xxx@163.com';
my $msg = MIME::Lite->new(
From => ‘xxx@163.com',
To => ‘chenqing663@foxmail.com',
Cc => ‘some@other.com, some@more.com',
Subject => ‘hello,my first mail from chenqing.org',
Type => ‘multipart/mixed',
Data =>' other data'
);
$msg->attach(
Type => ‘text/html',
Data => qq{
body>
这是我的 b>good/b> image:
img src=”cid:logo.png”>
/body>
},
);
$msg->attach(
Type => ‘image/png',
Disposition => ‘attachment',
Filename => ‘other.png',
Id => ‘logo.png',
Path => ‘/home/king/perl/logo.png'
);
MIME::Lite->send(‘smtp', $host, Timeout=>60, AuthUser=>$user, AuthPass=>$pass);
$msg->send;