画像を埋め込んだHTMLメールの出し方
MIME::Lite を使えば簡単に画像埋め込みのHTMLメールが出せる。
use strict; use warnings; use MIME::Lite; my $img = "foo.gif"; my $msg = MIME::Lite->new( From =>'yoshifumi1975@example.com', To =>'yoshifumi1975@example.com', Subject =>"HTML mail with image file", Type =>'multipart/related' ); #埋め込みたい画像のsrcは、以下のように頭に"cid:"を付ける。 $msg->attach(Type =>'text/html', Data =>qq( <html><body><img src="cid:$img"></body></html> ), ); #埋め込みたい画像をここで追加する。Idには、上の"cid:"のところと合わせる。 $msg->attach(Type =>'image/gif', Id =>"<$img>", Path =>"/tmp/$img", Filename =>$img, Disposition => 'inline' ); $msg->send('smtp','localhost', Timeout=>60, Debug=>1);