Perlでメールを送信するときはEmail::Senderを使いましょうというお話

ことの経緯はEmail::MIME - Togetter
まとめると、Email::MIME->create()のところうまく書けば良いよ、というお話。

ところが今度はEmail::Send。Email::SendのPODには

WAIT! ACHTUNG!

Email::Send is going away... well, not really going away, but it's being officially marked "out of favor." It has API design problems that make it hard to usefully extend and rather than try to deprecate features and slowly ease in a new interface, we've released Email::Sender which fixes these problems and others. As of today, 2008-12-19, Email::Sender is young, but it's fairly well-tested. Please consider using it instead for any new work.

とある。よって、Email::Senderを使うのがよろしいみたい。

詳しい流れに関しては、第20回 Email::Sender:メールを送信する:モダンPerlの世界へようこそ|gihyo.jp … 技術評論社が詳しい。


サンプルコード

sendmailの-fオプションを明示して指定できるようにしているが、普通に使う分には$contents->{from}と$contents->{envelope_sender}は同一で良い(らしい)。エラーメール収集アドレスを別にしたい人は別にするとよい(らしい)。
モバイルでも文字化けせずに送信可。(Docomoのみ確認済み、他キャリアの動作報告あればお願いします)
詳しい方はツッコミお願いします。

#!/usr/bin/perl

use strict;
use warnings;
use utf8;
use Encode;
use Email::MIME::Creator;
use Email::Sender::Simple qw/sendmail/;

my $contents = {
    from    => 'from@example.com',
    to      => 'to@example.com',
    subject => '電子メール',
    body    => 'サンプル',
    envelope_sender => 'envelope_sender@example.com',
};

my $mail = Email::MIME->create(
    header => [
        From    => $contents->{from},
        To      => $contents->{to},
        Subject => encode('MIME-Header-ISO_2022_JP', $contents->{subject}),
    ],
    attributes => { 
        content_type => 'text/plain',
        charset  => 'ISO-2022-JP',
        encoding => '7bit',
    },
    body_str => $contents->{body},
);

sendmail($mail, {from => $contents->{envelope_sender}});

exit;

1;
__END__