| 关键词: nbsp SMTP datasend LOG flock xxx Net open auth defined |
保存一下,在你的代码中require它即可=head need install module Net::SMTP_auth, you can type the following command at your shell prompt cpan -i Net::SMTP_auth =cut use Net::SMTP; use Fcntl qw/:DEFAULT :flock/; sub sendmail { my $msg = shift; my $smtp = Net::SMTP->new( Host => 'smtp.163.com', Timeout => 120, Debug => 1 ); if (defined $smtp) { $smtp->auth("xxx","xxx"); $smtp->mail("xxx\@163.com"); $smtp->to("xxx\@126.com"); $smtp->data(); $smtp->datasend("From: Server Monitor <xxx\@163.com> "); $smtp->datasend("To: SA team <sa\@abc.com> "); $smtp->datasend("Subject: Server Warnings "); $smtp->datasend(" "); $smtp->datasend("$msg "); $smtp->datasend(); $smtp->quit; } } sub printlog { my $str = shift; open LOG,'>>','log.txt' or die "$! "; flock LOG,LOCK_EX; print LOG "$str "; flock LOG,LOCK_UN; close LOG; } sub daemon { my $pid = fork(); die "can't fork progress: $! " unless defined $pid; exit 0 if $pid; setsid() or die "can't create a new session: $! "; open STDIN,'<','/dev/null'; open STDOUT,'>','/dev/null'; open STDERR,'>&',STDOUT; chdir "/"; umask 022; $ENV{'PATH'} = '/bin:/sbin:/usr/bin:/usr/sbin'; return $$; } 1; |
|
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系
[邮箱地址] 删除
|