socket(SH, PF_INET, SOCK_STREAM, 0) || die("ソケットエラー$!");
# 接続
connect(SH, $struct) || die("接続失敗$!");
select(SH); $| = 1; select(STDOUT);
$respons = <SH> ;
unless($respons =~ /^220/)
{
close(SH); die("接続失敗$!");
}
# ----- #
# コマンドの送信
# ----- #
# HELO コマンドの作成、送信
$command = "HELO $server¥r¥n";
print SH $command ;
$respons = <SH> ;
&decode(¥$respons) ;
unless($respons =~ /^250/)
{
close(SH); die("Command:HELO ・・・ FAIL $!");
}
# MAIL コマンドの作成、送信
$command = "MAIL FROM:$from¥r¥n";
print SH $command ;
$respons = <SH> ;
&decode(¥$respons) ;
unless($respons =~ /^250/)
{
print SH "RSET¥r¥n"; close(SH);
die("Command : MAIL ・・・ FAIL $!");
}
# RCPT コマンドの作成、送信
$command = "RCPT TO:$to¥r¥n";
print SH $command ;
$respons = <SH> ;
&decode(¥$respons) ;
unless($respons =~ /^25[01]/)
{
print SH "RSET¥r¥n"; close(SH);
die("Command : RCPT ・・・ FAIL $!");
}
# DATA コマンドの作成、送信
$command = "DATA¥r¥n";
print SH $command ;
$respons = <SH> ;
&decode(¥$respons) ;
unless($respons =~ /^354/){
print SH "RSET¥r¥n"; close(SH);
die("Command : DATA ・・・ FAIL $!");
}
# ----- #
# ヘッダー、本文の送信
# ----- #
# 文字コードの変換
&jcode'convert(*send_data,'jis');
# コマンドの作成、送信
$command = "$send_data¥r¥n.¥r¥n";
print SH $command ;
$respons = <SH> ;
&decode(¥$respons) ;
unless($respons =~ /^250/){
print SH "RSET¥n"; close(SH);
die("本文、ヘッダーの送信失敗$!");
}
# QUIT コマンドの作成、送信