用到的库:Net::SMTP;这个可以在cpan上找得到。
另外在windows下安装perl的库可以使用ppm方法。
在command line里面输入ppm会出现Perl Package Manager。
找到你所需要安装的库选择“File”->"Run task"就可以了。
看个发送邮件的简单例子:
sub SendEmail($$){
my $emailfrom="";
my ($to,$day) = @_;
my $mailhost='**.**';#邮件服务器的地址
my $subject = "主题";
my $text = "发送的内容“;
my $smtp = Net::SMTP->new($mailhost,Timeout=>120,Debug=>0);
$smtp->mail($emailfrom);
$smtp->to($to);#收件人
$smtp->data();
$smtp->datasend("To:$to/n");
#$smtp->datasend("From: $mailfrom/n");
$smtp->datasend("Subject: $subject/n");
#$smtp->datasend("/n");
# Send the message
$smtp->datasend("$text/n/n");
#Send the termination string
$smtp->dataend();
$smtp->quit;
}
调用该方法的时候可能会出现 can not call the methond mail() at line **
出现这个的原因有可能是mail server 无法ping 通。
open File,'+>>',$filename;#以追加的方式打开文件
print File "$content","/n";#往文件中写内容
close File;
perl解析xml文件:
用到的库:use XML::Simple;
看个例子:
# read XML file
print "begin to parse xml configure files..../n";
my $xml = new XML::Simple;
my $data;
if (-e "config.xml")
{
$data = $xml->XMLin("config.xml");
}else{
die "Could not find config.xml file! please validate it exists/n";
}
$username = $data->{usrname};
$password = $data->{pwd};
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。