#!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; use Encode; use Net::POP3; use Net::SMTP; print "Content-type: text/html;\n\n"; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $year += 1900; $mon += 1; if ($hour =~ /^[0-9]$/){ $hour = "0" . $hour; } if ($min =~ /^[0-9]$/){ $min = "0" . $min; } if ($mon =~ /^[0-9]$/){ $mon = "0" . $mon; } if ($mday =~ /^[0-9]$/){ $mday = "0" . $mday; } if ($sec =~ /^[0-9]$/){ $sec = "0" . $sec; } my $s_message = ""; my $ua = new LWP::UserAgent("agent" => "Mozilla/5.0 (Windows NT 6.1; rv:6.0.2) Gecko/20100101 Firefox/6.0.2"); my $res = $ua->get("http://www.jma.go.jp/jp/warn/329_table.html"); my $content = $res->content; my @csp1 = split(//,$content); my @csp2 = split(/<\/table/,$csp1[1]); my @csp3 = split(/
<\/a>名古屋市<\/a><\/td>/,$csp2[0]); my @csp4 = split(/<\/tr>/,$csp3[1]); my @csp5 = split(//,$csp4[0]); foreach(@csp5){ $_ =~ s/<\/td>//; } my $data = $csp5[3]; if (-d "bou"){ if ($data eq ""){ $s_message = <<"EOM"; $mon月$mday日 $hour:$min 名古屋市の暴風警報が解除されました。 EOM rmdir("bou"); } } else { if ($data ne ""){ $s_message = <<"EOM"; $mon月$mday日 $hour:$min 名古屋市に暴風警報が発令されました。 EOM mkdir("bou"); } } if ($s_message eq ""){ print "DONE $mon/$mday $hour:$min $sec"; exit; } my $pop = new Net::POP3("POPサーバー"); if($pop->login('POPユーザー名', 'POPパスワード') >= 0) { $pop->quit; } else { die "POP3 ERROR\n"; } my $from = '送信元アドレス'; my $to = '宛先アドレス'; my $subject = "件名"; my $msg = $s_message; Encode::from_to($subject,"utf8","ISO-2022-JP"); Encode::from_to($msg,"utf8","ISO-2022-JP"); my @bccl = ('BCCアドレス1'); #BCCを追加する場合は↑の配列に要素を追加 my $smtp = new Net::SMTP("SMTPサーバー"); $smtp->mail($from); $smtp->to($to); $smtp->bcc(@bccl); $smtp->data(); $smtp->datasend("From:$from\n"); $smtp->datasend("Subject:$subject\n");; $smtp->datasend("Content-Type: text/plain;charset=\"ISO-2022-JP\"\n\n"); $smtp->datasend("$msg\n"); $smtp->dataend(); $smtp->quit; print $s_message;