#!/usr/bin/perl -w ### # Start up a SMTP server, accept messages, and write them to the telegraph. # # Configuration params. ### $host = '10.8.1.3'; $port = '25'; $tty = '/dev/ttyUSB0'; $baud = '9600'; $parity = 'none'; $databits = 8; $stopbits = 1; $handshake = 'rts'; use Device::SerialPort; use Net::SMTP::Server; use Net::SMTP::Server::Client; use Email::Simple; ### # End configuration params. ### # # Configure the serial port. # $ob = Device::SerialPort->new ($tty) || die "Can't Open $tty: $!"; $ob->baudrate($baud) || die "failed setting baudrate"; $ob->parity($parity) || die "failed setting parity"; $ob->databits($databits) || die "failed setting databits"; $ob->stopbits($stopbits) || die "failed setting stopbits"; $ob->handshake($handshake) || die "failed setting handshake"; $ob->write_settings || die "no settings"; # # Create a new SMTP server. # $server = new Net::SMTP::Server($host, $port); # # Loop on accepting connections. # while($conn = $server->accept()) { my $client = new Net::SMTP::Server::Client($conn) || croak("Unable to handle client connection: $!\n"); $client->process; $mail = Email::Simple->new($client->{MSG}); # # Open just long enough to write our message in case someone else wants to # write directly to the telegraph too. # open (TTY, ">$tty") || die "can't open $tty: $!"; print TTY "From: " . $mail->header("From") . "\n\n"; if ($mail->header("Subject")) { print TTY "Subject: " . $mail->header("Subject"). "\n\n"; } if ($mail->body) { print TTY $mail->body . "\n\n"; } print TTY "STOP\n\n\n\n"; close (TTY); }