Hi Friends
Friday evening I heard a New that there is a change of MTA on our
WebServer. And then all my Perl scripts running on our WebServer refuse to
send me any stats / logs by email. And this gave me a jolt on Saturday
morning. I requested our Admin to send me docs related to our new MTA and
got the copy odf the same immediately. I opened my general purpose
sub-routine file modified mail sending part accordingly and again all my
scripts started sending me mails again. WOW but what happens if there is
change of MTA again and again and again.
So I decided to write a simple SMTP program which makes a socket connection
to the specified port and send mail irrespective of a MTA.
I started with the following code.
===============================================
# Please note my system runs Win2k + Activestate Perl
# And My Server Red Hat 6.2
===============================================
#!/usr/bin/perl -w
# use packages
use strict;
use IO::Socket;
# Data Variables
my ($SMTP_Server) = "10.10.10.10";
my ($SMTP_Port) = "25";
my ($CR) = "\r\n";
my $Socket;
# Mail Related Data
my $from = "joel\@testlinux.net";
my $to = "joel\@testlinux.net";
# Open Socket - SMTP Connection
$Socket = IO::Socket::INET->new(PeerAddr => "$SMTP_Server",
PeerPort => "smtp($SMTP_Port)",
Proto => "tcp",
Type => "SOCK_STREAM")
or die "Error : Cannot Open SMTP Socket. Reason : $!";
# set buffering off or autoflush
$|=1;
# say hello the mail host
# print $Socket "HELO $SMTP_Server" . $CR;
# Send Mail Command
# mail from
print $Socket "MAIL FROM: $from" . $CR;
# mail to
print $Socket "RCPT TO: $to" . $CR;
# Data command
print $Socket "DATA" . $CR;
# test message
print $Socket "Test Message" . $CR;
print $Socket "." . $CR;
#quit SMTP Session
print $Socket "QUIT" . $CR;
# Close Connection
close $Socket;
# Print Socket Close
print "SMTP Socket Closed" . $CR;
===============================================
Problem : and the mail is received by me immediately
but it gives To: as undisclosed-recipients
Help : a) Where did I go wrong in my code ?
b) Any guideline on how to improve my code
c) Any guidelines on attaching file(s)
===============================================
Date: Sat, 11 Aug 2001 12:24:00 +0000 (/etc/localtime)
From: [EMAIL PROTECTED]
To: undisclosed-recipients: ;
Test Message
===============================================
Thanks & Regards
Joel
!----- PostMaster AvAc Certified Virus Free Mail -----!
Command Engine Ver :14 4.073 Updated Until 03-Aug-2001