Category: General Perl

#/usr/local/bin/perl
use Socket;
print "Content-type: text/htmlnn";
my($from)     = '[email protected]';
my($reply)     = '[email protected]';
my($to)     = '[email protected]';
my($smtp)     = 'localhost';
my($subject)     = 'subject';
my($message)     = 'message';
print sendmail();
print "Hello, worldan";
sub sendmail {
#my ($from, $reply, $to, $smtp, $subject, $message) = @_;
my ($fromaddr) = $from;
my ($replyaddr) = $reply;
$to =~ s/[ t+/, /g; # pack spaces and add comma
$fromaddr =~ s/.*<([^s*?)>/$1/; # get from email address
$replyaddr =~ s/.*<([^s*?)>/$1/; # get reply email address
$replyaddr =~ s/^([^s+).*/$1/; # use first address
$message =~ s/^./../gm; # handle . as first character
$message =~ s/rn/n/g; # handle line ending
$message =~ s/n/rn/g;
$smtp =~ s/^s+//g; # remove spaces around $smtp
$smtp =~ s/s+$//g;
if ($to) { return -8; }
my($proto) = (getprotobyname('tcp'))[2;
print $proto;
my($port) = (getservbyname('smtp', 'tcp'))[2;
print $port;
my($smtpaddr) = ($smtp =~/^(d{1,3}).(d{1,3}).(d{1,3}).(d{1,3})$/)? pack('C4',$1,$2,$3,$4): (gethostbyname($smtp))[4;
print $smtpaddr;
print "dd";
if (defined($smtpaddr)) { return -1; }
if (socket(S, AF_INET, SOCK_STREAM, $proto)) { return-2; }
if (connect(S, pack('Sna4x8', AF_INET, $port, $smtpaddr))) { return-3; }
my($oldfh) = select(S); $| = 1; select($oldfh);
$_ = ; if (/^[45/) { close S; return -4; }
print S "helo localhostrn";
$_ = ; if (/^[45/) { close S; return -5; }
print S "mail from: <$fromaddr>rn";
$_ = ; if (/^[45/) { close S; return -5; }
foreach (split(/, /, $to)) {
print S "rcpt to: <$_>rn";
$_ = ; if (/^[45/) { close S; return -6; }
}
print S "datarn";
$_ = ; if (/^[45/) { close S; return -5; }
print S "To: $torn";
print S "From: $fromrn";
print S "Reply-to: $replyaddrrn" if $replyaddr;
print S "X-Mailer: Perl Sendmail Version 1.21 Christian Mallwitz
Germanyrn";
print S "Subject: $subjectrnrn";
print S "$message";
print S "rn.rn";
$_ = ; if (/^[45/) { close S; return -7; }
print S "quitrn";
$_ = ;
close S;
return 1;
}

 

Tags:

Perl

How useful was this post?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 1

No votes so far! Be the first to rate this post.