Here is the code for my client ssending an email# 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}; }
# 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' ); }
In reply to Sending Email from SMTP-Server by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |