Solved

Net::Smtp

Posted on 2004-04-16
8
415 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HTTP Error 502.2 - Bad Gateway 3 204
Port 80 requests 16 86
perl CPAN issue 3 98
Any syntax error for this clone.plscript 6 132
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…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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 explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

911 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

21 Experts available now in Live!

Get 1:1 Help Now