#!/usr/bin/perl -w

# This will be needed in order to connect to the remote POP3 server
use IO::Socket::INET;

# the mail host you want to send a mail to
#my $HOST = "e11.servers.net.au:25";
# my $HOST = "bne008m.server-mail.com:25";
 my $HOST = "mail.apfoods.com.au:25";

#my $HOST="p3.jamesmcdonald.id.au:25";
#my $HOST="localhost:25";

# person your sending it to
# my $to ="Administrator\@samedaycredit\.com\.au";
my $to = 'jmcdonald@apfoods.com.au';

#my $to ="james\@jamesmcdonald\.id\.au";

# email subject

my $timedate = localtime;

my $subject = "Test Email " . $timedate;

# email body
my $body = "This email serves as a test for the apfoods secondary";

# from address
my $from = "james\@jamesmcdonald\.id\.au";

# connect to the host
my $SOCKET = IO::Socket::INET->new( $HOST );

# Suck down the greeting and discard it
my $RESPONSE = <$SOCKET>;
$RESPONSE = <$SOCKET>;
$RESPONSE = <$SOCKET>;
$RESPONSE = <$SOCKET>;
$RESPONSE = <$SOCKET>;
$RESPONSE = <$SOCKET>;
$RESPONSE = <$SOCKET>;
$RESPONSE = <$SOCKET>;
$RESPONSE = <$SOCKET>;
$RESPONSE = <$SOCKET>;
$RESPONSE = <$SOCKET>;
$RESPONSE = <$SOCKET>;
$RESPONSE = <$SOCKET>;
$RESPONSE = <$SOCKET>;
$RESPONSE = <$SOCKET>;
# Start email chat with smtp server

# send helo
print $SOCKET "HELO mail.jamesmcdonald.id.au\r\n";
$RESPONSE = <$SOCKET>;
print $RESPONSE ;

# send mail from
print $SOCKET "mail from:". $from . "\r\n";
$RESPONSE = <$SOCKET>;
print $RESPONSE;

# send rcpt to
print $SOCKET "rcpt to:" . $to . "\r\n";
$RESPONSE = <$SOCKET>;
print $RESPONSE;

# send data
print $SOCKET "data\r\n";

# Pick up the response
$RESPONSE = <$SOCKET>;

print $RESPONSE;
print $SOCKET "from:" . $from . "\r\n";
print $SOCKET "To:" . $to . "\r\n";
print $SOCKET "Subject:" . $subject . "\r\n";
print $SOCKET $body . "\r\n";
print $SOCKET ".\r\n";
$RESPONSE = <$SOCKET>;
print $RESPONSE ;


# Log off
print $SOCKET "QUIT\r\n";

$RESPONSE = <$SOCKET>;
print $RESPONSE ;

# Close the socket
close($SOCKET);
