
xter74
Novice
Oct 15, 2002, 7:34 PM
Post #1 of 4
(267 views)
|
READ/OPEN TEXT -> SEND MAIL
|
Can't Post
|
|
Hi gurus, I'll need some help here. I had a subroutine which perform the open/read function and send it to a smtp server. I had tried several methods from the forum and books but I still can't get it to work. Thanks for the advise, the following is the codes that I have....... ********************************************************* sub capture { use strict; #my %hash = (); #open MAIL, "E:/Webs/blt.sgp.hp.com/share/cgi-bin/mail.log" or die $!; #read MAIL, $hash{key}, -s MAIL; open MAILLOG, "E:/Webs/blt.sgp.hp.com/share/cgi-bin/mail.log" or die $!; read MAILLOG; #$inline = $_; #$inline = $hash; #$mail_msg .= $inline; $mail_msg = <MAILLOG>; &send_msg; sub send_msg { open LOG, '>> E:/Webs/blt.sgp.hp.com/share/cgi-bin/smtp.log' or die "Cannot open file"; print LOG "\n===============================================\n"; print LOG scalar(localtime), " Started log.\n"; use IO::Socket; $SMTP_SERVER="ctss21.sgp.hp.com"; $remote = IO::Socket::INET->new( Proto => "tcp", PeerAddr => "$SMTP_SERVER", PeerPort => "smtp(25)", ) || die "cannot connect to SMTP port on $SMTP_SERVER\n"; $remote->autoflush(1); $inline = <$remote>; if( $inline !~ /^220/ ) { print LOG "Didn't get 220 response: $inline"; return; } print LOG $inline; #print "<br>sending: ", "HELO $SMTP_SERVER\n"; print $remote "HELO $SMTP_SERVER\n"; $inline = <$remote>; if( $inline !~ /^250/ ) { print LOG "Didn't get 250 response at HELO: $inline"; return; } print LOG "$inline"; #print "<br>sending: ", "MAIL From: $src_addr\n"; print $remote "MAIL From: ap-blt_support\@hp.com\n"; $inline = <$remote>; if( $inline !~ /^250/ ) { print LOG "Didn't get 250 response at MAIL: $inline"; return; } print LOG "$inline"; print "<br>sending: ", "RCPT To: $dst_addr\n <BR>"; # print $remote "RCPT To: $dst_addr\n"; print $remote "RCPT To: arsystem\@uspsgn01.sgp.hp.com \n"; $inline = <$remote>; if( $inline !~ /^250/ ) { print LOG "Didn't get 250 response at RCPT: $inline"; return; } print LOG "$inline"; #print "<br>sending: ", "DATA\n"; print $remote "DATA\n"; $inline = <$remote>; if( $inline !~ /^354/ ) { print LOG "Didn't get 354 response at DATA: $inline"; return; } print LOG "$inline"; print "\n============>$inline"; print $remote $mail_msg; print "\n\n=========>>>>$mail_msg"; print $remote "\n.\n"; # Accepted for delivery message $inline = <$remote>; print LOG $inline; print $remote "QUIT\n"; $inline = <$remote>; print LOG $inline; } close MAILLOG; }
|