用perl发送内容是html(超文本)格式邮件,有两种方法:
1、MIME::Lite::HTML;
2、Mail::Sender
首先都需要安装perl的这两个模块:
1、(较好,中文没有乱码)
#!/usr/bin/perl -w
use lib "/root/.cpan/build/MIME-Lite-HTML-1.23-8I0tF6/blib/lib";
use strict;
use MIME::Lite;
use MIME::Lite::HTML;
use Date::Parse;
# SendTo email id
my $email = ;
my $file = "/...../hh.html";
# create a new MIME Lite based email
my $mailHTML = MIME::Lite::HTML->new
(
Subject => "html test",
From => ,
To => $email,
HTMLCharset => 'GB2312',
);
my $MIMEmail = $mailHTML->parse("");
$MIMEmail->send;
2、(可能对html的解析出现遗漏,而使得邮件局部中文出现乱码)
#! /usr/local/bin/perl -w
use Mail::Sender;
$htmlfile = "hh.html";# sign.html 是已经编辑好的 html 文本的路径。
open IN, $htmlfile or die "Cannot open $htmlfile : $!\n";
$sender = new Mail::Sender {smtp => 'smtp.xxxx.net'};
$sender->Open({ from => , to => , subject => 'html test',
headers => "MIME-Version: 1.0\r\nContent-type: text/html\r\nContent-Transfer-Encoding: 7bit"
}) or die $Mail::Sender::Error,"\n";
while () { $sender->Send($_) };
close IN;
$sender->Close();
阅读(3112) | 评论(0) | 转发(0) |