MT::Mail自体には添付ファイル付のメールを組み立てる機能はないが、自分でヘッダーやBodyを作成してパラメータとして渡すことで、送信することはできる。
確認環境
- MovableType 6.0
- MIME::Entity (MIME-tools)
MT5でも動くと思う・・・たぶん・・・
サンプルコード
試しにmtのreadme.htmlとロゴを添付している。便宜置き換えのこと。
my $recipient = 'taro@test.host';
my $subject = '添付テスト';
my $text = "ファイル送信テスト\nほげほげ";
require MIME::Entity;
my $mime = MIME::Entity->build(
Type => 'text/plain;charset="iso-2022-jp"',
Data => [$text],
Encoding => "7bit",
);
$mime->attach(
Path => '/var/www/html/mt60/mt/readme.html',
Type => 'text/html',
Encoding => '-SUGGEST'
);
$mime->attach(
Path => '/var/www/html/mt60/mt/mt-static/images/chromeless/mt_logo.png',
Type => 'image/gif',
Encoding => '-SUGGEST'
);
my $head = $mime->head;
my %header = (
To => $recipient,
Subject => $subject,
'Content-Type' => $head->get( 'Content-Type' ),
);
my $body = $mime->stringify_body;
MT::Mail->send(\%header, $body)
or die MT::Mail->errstr;