Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Net::Smtp

Posted on 2004-04-16
8
Medium Priority
?
424 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
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 1000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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

879 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