# CLIENT use warnings; use strict; use Net::SMTP my $SMTP_HOST = 'localhost'; sub send_mail { my ($from, $to_addr, $msg); $from = shift; $to_addr = shift; $msg = shift; # # Open a SMTP session # $smtp = Net::SMTP->new( $SMTP_HOST, 'Debug' => 1, # Change to a 1 to turn on debug messages ); if(!defined($smtp) || !($smtp)) { print "SMTP ERROR: Unable to open smtp session.\n"; return 0; } # # Pass the 'from' email address, exit if error # if (! ($smtp->mail( $from ) ) ) { return 0; } # # Pass the recipient address(es) # if (! ($smtp->recipient( ( ref($to_addr) ? @$to_addr : $to_addr ) ) ) ) { return 0; } # # Send the message # $smtp->data( $msg ); $smtp->quit; } sub main { send_mail( 'from@domain.com', 'to@domain.com', 'This is a test email.\n' ); }