I'm using the sample script for SMTP-Server from below:
# SERVER use warnings; use strict; use Net::SMTP::Server; use Net::SMTP::Server::Client; use Data::Dumper; our $host = $ARGV[0] || "0.0.0.0" ; our $server = new Net::SMTP::Server($host) || croak("Unable to open SMTP server socket"); print "Waiting for incoming SMTP connections on ".($host eq "0.0.0.0" +? "all IP addresses":$host)."\n"; $| = 1; while(my $conn = $server->accept()) { print "Incoming mail ... from " . $conn->peerhost() ; my $client = new Net::SMTP::Server::Client($conn) || croak("Unable to process incoming request"); if (!$client->process) { print "\nfailed to receive complete e-mail message\n"; next; } print " received\n"; print "From: $client->{FROM}\n"; my $to = $client->{TO}; my $toList = @{$to} ? join(",",@{$to}) : $to; print "To: $toList\n"; print "\n" ; print $client->{MSG}; }
Here is the code for my client ssending an email

# 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_add +r ) ) ) ) { 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' ); }

I've tried using Net::SMTP module to send an email but it complains everytime I set the SMTP server arg to localhost. Both scripts live on the same box. I basically need the ability to send an email from a PC that doesn't have an SMTP server...Any Ideas?

In reply to Sending Email from SMTP-Server by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.