私は自分が働いている場所で内部的にメールを送信するための小さなPerlアプリを書いていますが、添付ファイルに問題があります。さて、皆さんが「MIME :: Liteを使用してください」と叫んでいるのが聞こえますが、それは簡単ではありません。管理ルールにより、cpanからは何も使用できないと言われています...
とにかく、私はMIME :: Base64を使用して、送信する添付ファイルをエンコードしています。私は物事の電子メール側にNet::SMTPを使用しています。
エンコーディングはそのように行われます(Perldocページから直接):
my $encoded = "";
use MIME::Base64 qw(encode_base64);
open (FILE, "7857084216_9816ae9bec_b.jpg") or die "$!\n";
while (read(FILE, $buf, 60*57)) {
$encoded .= encode_base64($buf);
}
関連するNet::SMTPコードは次のとおりです。
use Net::SMTP;
$smtp = Net::SMTP->new("mailserver",
Hello => 'somedomain.com.au',
Timeout => 60,
Debug => 0,
);
$smtp->mail(<services\@somedomain.com.au>);
$smtp->to(<me\@somedomain.com.au>);
$smtp->cc(<another\@somedomain.com.au>);
$smtp->data();
$smtp->datasend("Subject: testing 123\n");
$smtp->datasend("To: me\@somedomain.com.au\n");
$smtp->datasend("CC: another\@somedomain.com.au\n");
$smtp->datasend("MIME-Version: 1.0\n");
$smtp->datasend("Content-type: multipart/mixed;\n\tboundary=\"$boundary\"\n");
$smtp->datasend("--$boundary\n");
$smtp->datasend("Content-type: text/html; charset=utf-8\n");
$smtp->datasend("\n");
$smtp->datasend("<p> Test Email!</p>\n");
$smtp->datasend("\n");
$smtp->datasend("--$boundary\n");
$smtp->datasend("Content-type: image/jpeg; name=\"7857084216_9816ae9bec_b.jpg\"\n");
$smtp->datasend("Content-ID: \n");
$smtp->datasend("Content-Disposition: attachment; filename=\"7857084216_9816ae9bec_b.jpg\"\n");
$smtp->datasend("Content-transfer-encoding: base64\n");
$smtp->datasend("\n");
$smtp->datasend("$encoded");
$smtp->datasend("\n");
$smtp->datasend("--$boundary--\n");
$smtp->dataend;
$smtp->quit;
現時点では、これらの電子メールを自分宛てに送信し、Outlook 2010を使用して読んでいます。画像(jpegなど)を送信するときは、まったく問題はありません。私が見る限り、すべてがOKバイトごとにデコードされているようです。 。プレーンテキストだけでdocxタイプのファイルを送信しているときは、すべて問題ないようです。しかし、画像が挿入されたdocxファイルを送信すると、ファイルが破損します。
メールの送信と添付の専門家ではないので、少し途方に暮れています。電子メールに添付するためにdocxファイルをどのようにエンコードする必要がありますか?どんな助けでもいただければ幸いです!
また、言及するのを忘れて、それに応じてコンテンツタイプを設定しようとしました:コンテンツタイプ:application / vnd.openxmlformats-officedocument.wordprocessingml.document