Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Checking SMTP ports.

by jdtoronto (Prior)
on Sep 21, 2006 at 16:30 UTC ( [id://574185]=perlquestion: print w/replies, xml ) Need Help??

jdtoronto has asked for the wisdom of the Perl Monks concerning the following question:

Esteemed monks,

I have an email client written in Perl/Tk which is embedded in a contact management application. When users configure email they dont necessarilly go to the ISP's documentation and follow the configuration information and they dont know that their ISP has blocked port 25 for spam prevention. Many of them have fully fledged hosted domains outside and have SMTP servers listening on ports 857 or 587. But they aren't sure what to do.

So they put nothing in the box. Then they wonder why email doesn't get sent.

I could have net::SMTP try to connect on port 25 if their is nothing supplied, to test for connectivity. Is there a simpler way?

jdotronto

Replies are listed 'Best First'.
Re: Checking SMTP ports.
by grep (Monsignor) on Sep 21, 2006 at 16:50 UTC
    If you want you can use Net::Telnet. Check the port and see if you get a 2xx back from the server.

    If the request was sucessful each line should be prepended by a 2xx status code and SMTP in the line.

    $line =~ /^2\d\d .*SMTP/ should work as a rudimentary test for the first line back.

    Update:

    use strict; use warnings; use Net::Telnet; my $tel = Net::Telnet->new(-host => 'localhost', -port => 25, -errmode + => 'return') or die "Port not available\n"; my $rtn = $tel->getline() or die "No Reponse\n"; print $rtn =~ /^2\d\d .*SMTP/ ? 'OK' : 'Fail';


    grep
    Mynd you, mønk bites Kan be pretti nasti...
Re: Checking SMTP ports.
by dtr (Scribe) on Sep 21, 2006 at 18:12 UTC

    There are all kinds of checks that you could do. You could try to ping the host (Net::Ping) and see if that works - although that doesn't test that port 25 is open. You could try to connect to port 25 - but that doesn't guarantee that it's actually a mail server listening, or that your connection hasn't been redirected to the ISP's mail server (which might require SMTP Auth, limit who you can send as, etc).

    I would think that the only safe, robust way of checking would be to send a test email from the user to themselves, and include some kind of id in the body so that you know that it's been sent properly. You can then immediately delete that email once you see it. This will allow you to test both their SMTP and POP/IMAP settings at the same time, and uses modules that you've probably got installed anyway, rather than introducing something new.

      I already have Net::Ping check that there is a machine at the other end. What I need to do is offer a Check Server button where they enter the server details.

      However your idea of looping an email around is a good one, I will give it some thought.

      jdtoronto

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://574185]
Approved by grep
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-24 23:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found