作成 2016.03.03
更新 2016.03.03
Perl でメールサンプル
日本語非対応。スパムフィルター回避版。
送達確認等とりあえず送りたい人向けです。
#!/usr/bin/perl

use strict;
use warnings;
use POSIX;
use locale;

my $sendmail = '/usr/sbin/sendmail';
my $hostname = `hostname`;
$hostname =~ s/[\r\n]//g;
my $from = 'user01@'.$hostname;
my $to = 'user01@example.com';
my $subject = 'test from '.$hostname;
my $old_locale = setlocale(LC_TIME);
setlocale(LC_TIME,'C');
my $datetime = strftime("%a, %d %b %Y %H:%M:%S %z", localtime());
setlocale(LC_TIME,$old_locale);
my $msg = <<"_TEXT_";
test mail.
_TEXT_
my $printdata = <<"_PRINT_";
Date: $datetime
From: $from
To: $to
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
Reply-to: $from
Subject: $subject

$msg
_PRINT_

# print $printdata;
open(SDML,"| $sendmail -t -i");
print SDML $printdata;
close(SDML);
タグ: Perl

©2004-2017 UPKEN IPv4