Solved

Net::Smtp

Posted on 2004-04-16
8
417 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…

840 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