我要寄郵件,直接把圖片秀在信件內容上面,可以直接觀看,怎麼用 perl 程式作出來,
就拿 MIME::Lite 這個套件來用,程式碼如下
use strict; my $output =<<EOF; <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> <table border="0" cellpadding="2" cellspacing="1" bgcolor="gray"> <tr bgcolor="white"> <td>以下為圖片</td> </tr> <tr bgcolor="white"> <td><img src="cid:2014-02-11.png"></td> </tr> </table> </body> </html> EOF use MIME::Lite; my $msg = MIME::Lite->new( From =>'[email protected]', To =>'[email protected]', Subject =>"內嵌圖片", Type =>'multipart/mixed' ); $msg->attach( Type => 'text/html;charset=utf-8', Encoding => 'quoted-printable', Data => qq{$output} ); $msg->attach( Type => 'image/gif', Id => "2014-02-11.png", # 跟上方的 html 的 img src 的 cid 要配對 Path => "2014-02-11.png", # 實際檔案 ); $msg->send('smtp','localhost',Debug=>1);
留言