Solved

Net::Smtp

Posted on 2004-04-16
8
419 Views
Last Modified: 2010-03-04
I want to capture the output of a telnet session on port 25 for a number of hosts.  A colleague suggested that I use the Net::Smtp command with debugging; however, I don't quite now how to tackle it.  TIA for your help.
0
Comment
Question by:uluttrell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 36

Expert Comment

by:Zyloch
ID: 10846819
If you want to capture the output of a telnet session on port 25, why would you use Net::Smtp? I don't claim to be an expert, and I know I'm not, but SMTP is the Simple Mail Transfer Protocol Client primarily used to send mail...
0
 
LVL 48

Expert Comment

by:Tintin
ID: 10848551
To clarify, are you trying to connect to port 25 on a variety of hosts and capture the SMTP session?

If so, then something like:

#!/usr/bin/perl
use strict;

use Net::SMTP;

my @mailhosts qw(mailhost1 mailhost2 mailhost3);

for my $host (@mailhosts) {
    my $smtp = Net::SMTP->new(Host=>$host,debug=>1);

    $smtp->mail($ENV{USER});
    $smtp->to('postmaster');

    $smtp->data();
    $smtp->datasend("To: postmaster\n");
    $smtp->datasend("\n");
    $smtp->datasend("A simple test message\n");
    $smtp->dataend();

    $smtp->quit;
}
0
 

Author Comment

by:uluttrell
ID: 10848763
Tintin, Yes you are correct; however, I mainly want to see whether I get a banner or not.  How would this be accomplished?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 48

Expert Comment

by:Tintin
ID: 10852372
Try:

#!/usr/bin/perl
use strict;

use Net::SMTP;

my @mailhosts =  qw(mailhost1 mailhost2 mailhost3);

for my $host (@mailhosts) {
    my $smtp = Net::SMTP->new(Host=>$host,debug=>1);
    print $smtp->banner;
}

Are you trying to use the script to check if a SMTP server is available.  If so, why not use a tool like Big Brother or Nagios?
0
 

Author Comment

by:uluttrell
ID: 10855852
TinTin, I am trying to see whether a SMTP server is available; however, the Net::SMTP module is not installed :(  I will attempt to script this via a shell script.  Any suggestions for a shell script?
0
 
LVL 48

Accepted Solution

by:
Tintin earned 250 total points
ID: 10856310
If you don't want to use one of the many monitoring packages like I mentioned, you could use the telnet or expect modules (although I suspect they're not installed either).

As for a shell script, you can do some things like:

#!/bin/sh

for mailhost in host1 host2 host3 host4
do
   echo "quit" | telnet $mailhost 25
done

This is not a foolproof way if the connection gets hung or the server isn't available.

Are you going to be monitoring other things apart from SMTP servers?
0
 

Author Comment

by:uluttrell
ID: 10856569
I won't be monitoring other things apart from SMTP servers.  I will give this a try and let you know.
0
 

Author Comment

by:uluttrell
ID: 10865015
Tintin, Thanks for your help.  I greatly appreciate it.  It was most helpful.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question