Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

turn on debug below perl code

abcdef1abcdef1 Posts: 2Member
How to turn on debug in function sendSMTP ??
What is the fucntion var $debug ??

[code]
#!/usr/bin/perl -w

use Socket;
use strict;

my($mailTo) = 'chuikingman@yahoo.com.hk';
my($mailServer) = 'mail.hgcbroadband.com';

my($mailFrom) = 'medined@mtolive.com';
my($realName) = "chuikingman";
my($subject) = 'Test send_mail';
my($body) = "Test Line One.
Test Line Two.
";

$main::SIG{'INT'} = 'closeSocket';

my($proto) = getprotobyname("tcp") || 6;
my($port) = getservbyname("SMTP", "tcp") || 25;
my($serverAddr) = (gethostbyname($mailServer))[4];

die('gethostbyname failed.') unless (defined($serverAddr));

socket(SMTP, AF_INET(), SOCK_STREAM(), $proto)
or die("socket: $!");

my $packFormat;
$packFormat = 'S n a4 x8'; # Windows 95, SunOs 4.1+
#$packFormat = 'S n c4 x8'; # SunOs 5.4+ (Solaris 2)

connect(SMTP, pack($packFormat, AF_INET(), $port, $serverAddr))
or die("connect: $!");

select(SMTP); $| = 1; select(STDOUT); # use unbuffered i/o.

{
my($inpBuf) = '';

recv(SMTP, $inpBuf, 200, 0);
recv(SMTP, $inpBuf, 200, 0);
}
my $debug = 1 ;
sendSMTP(1, "HELO
");
sendSMTP(1, "MAIL From: <$mailFrom>
");
sendSMTP(1, "RCPT To: <$mailTo>
");
sendSMTP(1, "DATA
");

send(SMTP, "From: $realName
", 0);
send(SMTP, "Subject: $subject
", 0);
send(SMTP, $body, 0);

sendSMTP(1, "
.
");
sendSMTP(1, "QUIT
");

close(SMTP);

sub closeSocket { # close smtp socket on error
close(SMTP);
die("SMTP socket closed due to SIGINT
");
}

sub sendSMTP {
my($debug) = shift;
#my($debug) = 1;
my($buffer) = @_;

print STDERR ("> $buffer") if $debug;
send(SMTP, $buffer, 0);

recv(SMTP, $buffer, 200, 0);
print STDERR ("< $buffer") if $debug;

return( (split(/ /, $buffer))[0] );
}




[/code]
Sign In or Register to comment.