SMPT Connection Errors

Discussion in 'Perl Misc' started by Simon Andrews, Dec 1, 2004.

  1. I have a strange strange problem setting up some CGI scripts on a new
    webserver which seem to boil down to the way that different modules
    connect to an SMTP server.

    I have two scripts which send email. One uses Mail::Sendmail and the
    other uses MIME::Lite (which itself uses Net::SMTP for the connection).
    The Mail::Sendmail script works fine, both from a commandline and when
    run as a CGI script. The MIME::Lite script works fine from the command
    line, but fails when run as a CGI.

    Both scripts are pointing to the same SMTP server and both work fine
    when run from our old webserver.

    I am at a complete loss to debug this problem. The Net::SMTP connect
    fails during the new() statement, and I don't get any debugging output.
    Since both scripts are just opening a socket on port 25 I can't see what
    could be set in the webserver configuration which would stop one from
    working.

    The symptoms suggest this must be a webserver configuration problem but
    I don't know how to get any more details about the failed connection so
    I can try to track down exactly what's failing.

    I've included the test scripts I used. The first one fails, but the
    second one works. Beyond the test in the die statement I get nothing in
    the log file when the first script fails.

    ###############################################
    #!perl
    use warnings;
    use strict;
    use CGI;
    use CGI::Carp qw(fatalsToBrowser);
    use NET::SMTP;

    $NET::SMTP::Debug = 1;

    open (STDERR,'>','E:\Errors\smtp_log.txt') or die "Can't write to
    logfile: $!";

    my $q = new CGI;

    print $q -> header();
    print $q -> start_html();
    print "<pre>";

    print "Connecting to smtp server\n";

    my $smtp = Net::SMTP->new('our.mail.server',Debug => 1) or die "Can't
    connect to mail server";

    $smtp -> mail('');

    $smtp -> to('');
    $smtp -> data();
    $smtp -> datasend("To: simon.andrews\@bbsrc.ac.uk\n\n");
    $smtp -> datasend("Test message\n\n");
    $smtp -> dataend();

    $smtp -> quit();

    print "Finished connecting\n";


    print "</pre>";
    print $q -> end_html();

    ##################################################

    #!perl
    use warnings;
    use strict;
    use CGI;
    use CGI::Carp qw(fatalsToBrowser);
    use Mail::Sendmail;

    open (STDERR,'>','E:\Errors\sendmail_log.txt') or die "Can't write to
    logfile: $!";


    my $q = new CGI;

    print $q -> header();
    print $q -> start_html();
    print "<pre>";

    print "Connecting to smpt server\n";

    $Mail::Sendmail::mailcfg{debug} = 6;

    my %mail = (To => '',
    From => '',
    Message => 'This is a test',
    smtp => 'our.mail.server',);

    sendmail(%mail) or die "Can't send mail $Mail::Sendmail::error";

    print "Log says:\n";
    print $Mail::Sendmail::log;

    print "Finished connecting\n";

    print "</pre>";
    print $q -> end_html();
     
    Simon Andrews, Dec 1, 2004
    #1
    1. Advertising

  2. Simon Andrews wrote:
    > I have a strange strange problem setting up some CGI scripts on a new
    > webserver which seem to boil down to the way that different modules
    > connect to an SMTP server.
    >
    > I have two scripts which send email. One uses Mail::Sendmail and the
    > other uses MIME::Lite (which itself uses Net::SMTP for the connection).
    > The Mail::Sendmail script works fine, both from a commandline and when
    > run as a CGI script. The MIME::Lite script works fine from the command
    > line, but fails when run as a CGI.


    As always, having wrestled with this all morning we find the answer
    within 5 mins of posting to the newsgroups!

    It turns out that the reason it was failing was that the webserver user
    didn't have read access to c:\Windows\System32\drivers\etc\protocol
    which is just a list of protocols and port numbers. I don't know
    exactly where this access attempt comes from (IO::Socket?), but this
    causes the failure even if we explicity set a port number in the
    Net::SMTP connect statement.

    Hopefully this will be useful for someone else in the future.

    Cheers

    Simon.
     
    Simon Andrews, Dec 1, 2004
    #2
    1. Advertising

  3. Simon Andrews <> wrote:
    >
    > other uses MIME::Lite (which itself uses Net::SMTP for the connection).

    ^^^

    > use NET::SMTP;
    >
    > $NET::SMTP::Debug = 1;

    ^^^


    s/NET/Net/g; # ??


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Dec 1, 2004
    #3
  4. Tad McClellan wrote:
    > Simon Andrews <> wrote:
    >
    >>other uses MIME::Lite (which itself uses Net::SMTP for the connection).

    >
    > ^^^
    >
    >
    >>use NET::SMTP;
    >>
    >>$NET::SMTP::Debug = 1;

    >
    > ^^^
    >
    > s/NET/Net/g; # ??
    >


    Hmm. Interesting (and thanks for pointing it out!).

    As per my other post that wasn't the actual cause, but I'm surprised it
    didn't mess things up in other ways. I know that Windows can get away
    with the initial use having the wrong case due to the insensitive file
    system, but I'd have thought I'd have got a "Can't locate method new via
    package..." when I tried to create an object of that class? Running my
    test script now with NET rather than Net, everything works just fine!?

    Simon.
     
    Simon Andrews, Dec 1, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robert Strickland

    Intercept SMPT Email

    Robert Strickland, Jan 15, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    399
    Robert Strickland
    Jan 15, 2004
  2. Mark Goldin

    Errors, errors, errors

    Mark Goldin, Jan 17, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,027
    Mark Goldin
    Jan 17, 2004
  3. =?Utf-8?B?VGVycnkgSG9sbGFuZA==?=

    encrypt smpt section of web config

    =?Utf-8?B?VGVycnkgSG9sbGFuZA==?=, Oct 1, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    454
    =?Utf-8?B?VGVycnkgSG9sbGFuZA==?=
    Oct 1, 2007
  4. Simon Cheng

    POP-before-SMPT

    Simon Cheng, Nov 27, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    136
    Simon Cheng
    Nov 28, 2005
  5. L. Stern

    Problem with SMPT mail

    L. Stern, Jun 7, 2006, in forum: Perl Misc
    Replies:
    4
    Views:
    158
    L. Stern
    Jun 8, 2006
Loading...

Share This Page