in reply to Net::SMTP and debugging ?

Im guessing that you need to authenticate yourself with the SMTP server. Without seeing the full output of the conversation with the server (what you posted is not it) its hard to tell whats going wrong.

I suspect that your problem with debugging this may be that you are running this as a CGI and that Net::SMTP (because of its Net::CMD heritage) writes the conversation with the SMTP server to STDERR. I think you need to use CGI::Carp to get this to be redirected to your webserver error logs.

As a last point you may want to just go and install an email handling module like MIME::Lite and save yourself the hassle of talking to the SMTP server directly. However if authentication is the problem then MIME::Lite will unfortunately not be directly suitable until 3.02 comes out. However I am working on it.


---
demerphq

    First they ignore you, then they laugh at you, then they fight you, then you win.
    -- Gandhi


Replies are listed 'Best First'.
Re: Re: Net::SMTP and debugging ?
by peterr (Scribe) on Oct 04, 2003 at 12:47 UTC
    Im guessing that you need to authenticate yourself with the SMTP server. Without seeing the full output of the conversation with the server (what you posted is not it) its hard to tell whats going wrong.

    I will find out if I need to supply authentication. What I posted was all I saw in conversing with the server, nothing else was echoed back

    ... writes the conversation with the SMTP server to STDERR. I think you need to use CGI::Carp to get this to be redirected to your webserver error logs.

    Is there any method to get STDERR, at least, get echoed back to the terminal ? I will check out CGI::Carp, thanks.

    Does MIME::Lite handle attachments ? Wow, there are far too many modules for sending email, which one is easy/simple for a Perl novice like me. :)

    Thanks,

    Peter

Re: Re: Net::SMTP and debugging ?
by peterr (Scribe) on Oct 06, 2003 at 02:00 UTC
    Hi,

    Thanks for putting me onto CGI::Carp, it has been great to be able to see _where_ the script is crashing. I just directed the log file to a path I could view via a browser, as SSH access take foreever to load.

    I've now been able to use Net::SMTP successfully, once I put "localhost" as the domain/mailserver, it worked like a charm. The only problem I found was I could not do this

    $from = 'sales@domain.com'; $toaddress = 'fredflintstone@disney.com'; $name = 'Fred Flintstone'; $smtp->mail('$from\n"); $smtp->to("$toaddress\n");

    but got around the problem by putting email headers like this

    $smtp->data(); $smtp->datasend("To: $name <$toaddress>\n"); $smtp->datasend("Subject: Confirmation and Thankyou\n"); $smtp->datasend("X-Order-IP: $ENV{REMOTE_ADDR}\n"); $smtp->datasend("\n"); $smtp->datasend("Hi $name,\n");

    Peter

      Glad CGI::Carp was helpful. However I must say that I strongly discourage hand generating SMTP mails. Use MIME::Lite instead. Let it do the work of making sure things are set up correctly.

      The new version will have much more powerful features for handling SMTP transport, but you dont need any of those features from what I can tell.


      ---
      demerphq

        First they ignore you, then they laugh at you, then they fight you, then you win.
        -- Gandhi


        Glad CGI::Carp was helpful

        Yes, after seeing "premature end of scripts headers" for a long while, and _not_ knowing where it crashes, has been very fustrating. Now I can see warning messages, and for testing the email, I can see ALL the echos back from the email server.

        However I must say that I strongly discourage hand generating SMTP mails. Use MIME::Lite instead. Let it do the work of making sure things are set up correctly.

        Although the Net::SMTP has been working 100% okay for a small Perl script (about 170 lines, most of it email 'body'), when I added it to a much larger Perl script, as a sub routine, it is not working all the time. From the 'logs', the email server is talking okay, and I should get all the emails back, but I don't. On the converse, the 'feedback' form, which uses FormMail.pl and the CGI::NMS::Mailer::SMTP modules, it works 100% on 2 domains ??

        So, there is something strange happening with Net::SMTP, and because the emails are online order confirmations, I _really_ need them ALL to come to me first. I had a quick look at MIME:Lite, it looks very easy to use. We have Perl 5.61, so I hope it is installed, so that I can test it. The emails I'm sending aren't complex (attachments will be later), they are just a few standard email headers, and the body is a mixture of 'fixed' text, plus some text created from some MySQL work.

        Thanks, :)

        Peter

        Use MIME::Lite instead

        Well, thanks, a small one line test worked just fine, no authentication needed, and the headers look more like the (NMS) FormMail.pl headers. The website does state they have SENDMAIL, but they _actually_ use Exim. I just used the example for the headers and the body, and then

        $msg->send;
        Looks like that's all I need. As there is quite a lot of email 'body', is the best way to do multiple

        Data =>"Some test in the body part" )

        .. or some other preferred method, considering there are a few MySQL 'FOR' loops to build parts of the email body.

        Thanks,

        Peter