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);