Perl 通過SMTP發送正文爲HTML格式的郵件

Perl雖然有Net::SMTP模塊可以發送郵件,但是似乎只能發送純文本的郵件,這次的需求是將一個HTML網頁直接顯示在郵件正文中,因此搜索到了MIME::Lite模塊來實現這個功能。

use strict;
use MIME::Lite;

my $mailhost="smtp.163.com";
my $username="test\@163.com";
my $password="test";
my $data='
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> title </title>
</head>
<body>
<p>hello world</p>
</body>
</html>
';
my $msg=MIME::Lite->new(
	From=>"$username",
	To=>"$username",
	Subject=>"title",
	Type=>"text/html",
	Data=>"$data"
);
$msg->send('smtp',$mailhost,AuthUser=>$username,AuthPass=>$password);


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章