# This is a very simple module I wrote to allow Perl scripts to send # quick SMTP messages with a minimum of overhead. This module doesn't # require a local mail server to handle delivery. It makes a direct # connection to the recipient's SMTP port. # This probably violates RFC 2822, but it gets the job done. package TelnetEmail; use Exporter qw(import); our @EXPORT_OK = qw(telnet_email); use Net::Telnet(); use Net::DNS; use Sys::Hostname; sub telnet_email { # pass a hash containing to, from, subject and message values my $args = pop; my ($user,$domain) = split('@', $args->{to}); my @mx = mx($domain); my $mx = $mx[0]->exchange; my $telnet = new Net::Telnet(Host=>$mx, Port=>25); $telnet->open(); $telnet->waitfor('/220/'); $telnet->print('HELO ' . hostname); $telnet->waitfor('/250/') ; $telnet->print("MAIL FROM: <$args->{from}>"); $telnet->waitfor('/250/') ; $telnet->print("RCPT TO: <$args->{to}>"); $telnet->waitfor('/250/') ; $telnet->print("DATA From: $args->{from} Subject: $args->{subject} $args->{message} \n.\n"); $telnet->waitfor('/250/') ; $telnet->print('QUIT'); } 1;