模块创建并发送带 MIME 指定类型附件的邮件。MIME 是 Multimedia Internet Mail Extensions 的缩写,而且也是在邮件中附带各种文件文档的标准方式。
下面一段代码发送带MIME信息的附件,附件中的图片会在邮件客户端自动显示。
#! /usr/local/bin/perl -w
use MIME::Lite;
my $mailhost = "smtp.liaojl.com";
my $mailfrom = 'liaojl@liaojl.com';
# the recipient list
my @mailto = ('liaojl@liaojl.com', 'adminstrator@liaojl.com');
my $subject = "My Subject";
my $text = "The first line.\nThe second line.";
foreach my $mailto (@mailto) {
# Send the From and Recipient for the mail servers that require it
$msg = MIME::Lite->new(From => $mailfrom,
To => $mailto,
Subject => $subject,
Data => "abc",
Type => 'multipart/mixed');
$msg->attach(Type => 'image/jpeg',
Path => '/home/liaojl/win40.jpg',
Filename => 'gnat-face.jpg');
$msg->attach(Type => 'TEXT',
Data => 'I hope you can use this!');
$msg->send('smtp', 'smtp.liaojl.com');
}
这儿有几个有用的附件编码类型:
发送邮件的唯一两种方法是sendmail和Net::SMTP。调用send方法时,若第一个参数为"smtp",则用Net::SMTP发送邮件。send的其它参数都传给Net::SMTP。
Comments
There are currently no comments
New Comment