Net::SMTP problem

Discussion in 'Perl Misc' started by Matt, Aug 30, 2006.

  1. Matt

    Matt Guest

    have a simple few lines of Perl I'm trying to run from a cgi program
    to send some email.

    My code looks like:
    use Net::SMTP;
    my $email="mda\@x.com";
    my $msg="hello tst\n";
    $smtp = Net::SMTP->new('smtp.x.com');# or die "Unable to open
    the connection";
    $smtp->mail('');
    $smtp->to($email);
    $smtp->data($msg);
    $smtp->dataend();
    $smtp->quit;


    When I run the code via command line it works. When I run it via a cgi
    program from a webpage I get when it dies on the SMTP->new line:
    Can't call method "mail" on an undefined value


    Everything I"ve searched for says it is because my script cannot
    contact the smtp server, but that's not the case because when I run it
    via the command line, it works fine.


    It looks like it has to be some permisssion thing, either in sendmail
    or apache.


    Any thoughts?


    Thanks
     
    Matt, Aug 30, 2006
    #1
    1. Advertising

  2. On 30 Aug 2006 "Matt" <> wrote in
    news::

    > have a simple few lines of Perl I'm trying to run from a cgi
    > program to send some email.


    > My code looks like:
    > use Net::SMTP;
    > my $email="mda\@x.com";


    why not

    my $email = ''

    Saves escaping the @.

    > my $msg="hello tst\n";
    > $smtp = Net::SMTP->new('smtp.x.com');# or die "Unable to
    > open the connection";


    Why comment out the or die()? that will only get called if the
    Net::SMTP->new() fails, surely you want some form of error handling
    there.

    > $smtp->mail('');
    > $smtp->to($email);
    > $smtp->data($msg);
    > $smtp->dataend();


    That isn't a valid mail message. You need some headers.

    > $smtp->quit;
    >
    >
    > When I run the code via command line it works. When I run it via a
    > cgi program from a webpage I get when it dies on the SMTP->new
    > line: Can't call method "mail" on an undefined value


    > Everything I"ve searched for says it is because my script cannot
    > contact the smtp server, but that's not the case because when I
    > run it via the command line, it works fine.


    It probably is that you can't connect to (rather than contact) the
    server. Most servers run IP based authorisation, the webserver may
    well not have permissions to use it. Find the SMTP server of your
    webspace.

    --
    Graham Drabble
    http://www.drabble.me.uk/
     
    Graham Drabble, Sep 2, 2006
    #2
    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. Replies:
    3
    Views:
    1,095
    Roedy Green
    Jan 24, 2006
  2. Alex Hunsley
    Replies:
    4
    Views:
    3,506
    Tim Williams (gmail)
    Jun 29, 2004
  3. Raaijmakers, Vincent \(GE Infrastructure\)

    RE: sending of mail (smtp) - connection refused - but smtp serveris running!

    Raaijmakers, Vincent \(GE Infrastructure\), Jun 29, 2004, in forum: Python
    Replies:
    0
    Views:
    890
    Raaijmakers, Vincent \(GE Infrastructure\)
    Jun 29, 2004
  4. Copelandia Cyanescens

    smtplib.SMTP "no attributes SMTP"

    Copelandia Cyanescens, Jul 31, 2004, in forum: Python
    Replies:
    2
    Views:
    1,451
    Copelandia Cyanescens
    Jul 31, 2004
  5. tshad
    Replies:
    1
    Views:
    896
    bruce barker
    May 5, 2008
Loading...

Share This Page