Greets -
I'm trying to use socket commands to send email and I'm having some problems I thought someone might be able to help with.
When I send the below code, I get a blank email with nothing in the "To" field, no subject and no message. Any ideas?
################################
use Socket;
socket(SOCK, PF_INET, SOCK_STREAM, getprotobyname('tcp')); #set up the socket
connect(SOCK, sockaddr_in(25, inet_aton($server))); #connect to my server on port 25
select(SOCK); $| = 1; select(STDOUT); # use unbuffemiles i/o.
{
my($inpBuf) = '';
recv(SMTP, $inpBuf, 200, 0);
recv(SMTP, $inpBuf, 200, 0);
}
sendSMTP(0, "HELO $server\n");
sendSMTP(0, "MAIL From: <$config{'admin_address'}>\n");
sendSMTP(0, "RCPT To: <$to>\n");
sendSMTP(0, "DATA\n");
send(SOCK, "From: $from\r\n.\r\n", 0);
#send(SOCK, "Reply-To: $from\r\n.\r\n", 0);
send(SOCK, "Subject: $subject\n", 0);
send(SOCK, $message, 0);
#sendSMTP(0, "From: <$from>\r\n.\r\n");
#sendSMTP(0, "Reply-To: <$from>\r\n.\r\n");
#sendSMTP(0, "Subject: <$subject>\r\n.\r\n");
#sendSMTP(0, $message, 0);
sendSMTP(0, "\r\n.\r\n");
sendSMTP(0, "QUIT\n");
####################################
close(SOCK);
##################
# SendSMTP code
sub sendSMTP {
my($debug) = shift;
my($buffer) = @_;
print STDERR ("> $buffer") if $debug;
send(SOCK, $buffer, 0);
recv(SOCK, $buffer, 200, 0);
print STDERR ("< $buffer") if $debug;
return( (split(/ /, $buffer))[0] );
}
###################################
Again, the email gets sent but the 3 fields mentioned above are blank. Any help would be appreciated.
I'm running this on an NT box if that helps.
EDIT: Added a few other lines I previously left out just in case they're important.
I'm trying to use socket commands to send email and I'm having some problems I thought someone might be able to help with.
When I send the below code, I get a blank email with nothing in the "To" field, no subject and no message. Any ideas?
################################
use Socket;
socket(SOCK, PF_INET, SOCK_STREAM, getprotobyname('tcp')); #set up the socket
connect(SOCK, sockaddr_in(25, inet_aton($server))); #connect to my server on port 25
select(SOCK); $| = 1; select(STDOUT); # use unbuffemiles i/o.
{
my($inpBuf) = '';
recv(SMTP, $inpBuf, 200, 0);
recv(SMTP, $inpBuf, 200, 0);
}
sendSMTP(0, "HELO $server\n");
sendSMTP(0, "MAIL From: <$config{'admin_address'}>\n");
sendSMTP(0, "RCPT To: <$to>\n");
sendSMTP(0, "DATA\n");
send(SOCK, "From: $from\r\n.\r\n", 0);
#send(SOCK, "Reply-To: $from\r\n.\r\n", 0);
send(SOCK, "Subject: $subject\n", 0);
send(SOCK, $message, 0);
#sendSMTP(0, "From: <$from>\r\n.\r\n");
#sendSMTP(0, "Reply-To: <$from>\r\n.\r\n");
#sendSMTP(0, "Subject: <$subject>\r\n.\r\n");
#sendSMTP(0, $message, 0);
sendSMTP(0, "\r\n.\r\n");
sendSMTP(0, "QUIT\n");
####################################
close(SOCK);
##################
# SendSMTP code
sub sendSMTP {
my($debug) = shift;
my($buffer) = @_;
print STDERR ("> $buffer") if $debug;
send(SOCK, $buffer, 0);
recv(SOCK, $buffer, 200, 0);
print STDERR ("< $buffer") if $debug;
return( (split(/ /, $buffer))[0] );
}
###################################
Again, the email gets sent but the 3 fields mentioned above are blank. Any help would be appreciated.
I'm running this on an NT box if that helps.
EDIT: Added a few other lines I previously left out just in case they're important.