Solved

Net::Smtp

Posted on 2004-04-16
8
414 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
 
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
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…
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…
This video discusses moving either the default database or any database to a new volume.

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now