#!/usr/bin/perl use strict; use warnings; my $sendmail = '/usr/lib/sendmail'; my $mail_to = 'mobile@example.jp'; my $mail_from = 'mb@example.com'; { my ($from, $subject, $body) = &make_mail(); &sendmail($from, $subject, $body); } exit 0; sub make_mail { my ($from, $subject, $body); my $head_flag = 1; open (STDIN); while () { if ($head_flag) { if (/^$/) { $head_flag = 0; } elsif ((/^From:[^<]+<([^\@>]+)\@([^>]+)>/) || (/^From: ([^\@\s]+)\@([^\s]+)/)) { $from = $1 . '@' . $2; } elsif (/^Subject:/) { $subject = $_; } } else { $body .= $_; } } close (STDIN); return $from, $subject, $body; } sub sendmail { my ($from, $subject, $body) = @_; open (MAIL, "| $sendmail -t") || die "Can't open $sendmail"; print MAIL "To: $mail_to\r\n"; print MAIL "From: $mail_from\r\n"; print MAIL $subject; print MAIL "\r\n"; print MAIL "from $from\n"; print MAIL $body; close (MAIL); }