Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Sending mail on a bad server...

by TriggerDunpoe (Novice)
on Jun 27, 2004 at 14:05 UTC ( [id://369959]=perlquestion: print w/replies, xml ) Need Help??

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

I'm making an order form for a client, and at the end it's supposed to email the client with the user's information. I test this script on my server, and there it wouldn't email me using /usr/sbin/sendmail, so I tried Mail::Sendmail, and that didn't work either, so I tried Mail::Send, which worked. I put this on my client's server and none of these options work. Is there any way to send email through perl that's guaranteed to work on any server?

Replies are listed 'Best First'.
Re: Sending mail on a bad server...
by davido (Cardinal) on Jun 27, 2004 at 16:52 UTC

    Not sure if it's "Guaranteed", but there are a couple of other options:

    • Mail:Mailer allows you to specify the mail transport.
    • MIME::Lite allows you to specify that mail be sent without the use of any external transport, via direct SMTP connection. This module has its own transport, and thus will even work on a barebones Win32 system that lacks sendmail or equivilant.

    Dave

Re: Sending mail on a bad server...
by keszler (Priest) on Jun 27, 2004 at 14:59 UTC
    Guaranteed to work on any server? No.

    If sendmail is installed (vs another mailserver), is it in /usr/bin or elsewhere? If the Mail::Sendmail or Mail::Send modules are installed, are they properly configured? What mailserver accepts mail from the webserver running the perl processing the form? Does that mailserver accept mail from user 'nobody' or whatever UID is running the code?

Re: Sending mail on a bad server...
by andyf (Pilgrim) on Jun 27, 2004 at 20:29 UTC
    May I recommend Net::SMTP. Here's a piece of code that has been reliable since this time last year. Its very easy to understand.
    sub vianetsmtp { my $from = $_[0]; my $to = $_[1]; my $subject = $_[2]; my $body = $_[3]; $smtp = Net::SMTP->new ($maileroutrelay, Timeout => $mailerouttimeout, Debug => $maileroutdebug ) or logtofile ($logdir.'/usermailer',"can't create +new smtp mail object"); defined ($smtp) or die; my $domainmessg = $smtp->domain; my $bannermessg = $smtp->banner; $smtp->mail($from); $smtp->to($to); $smtp->data; $smtp->datasend("from:$from"); $smtp->datasend("\n"); $smtp->datasend("subject:$subject"); $smtp->datasend("\n"); $smtp->datasend("$body"); $smtp->datasend("\n"); $smtp->quit; undef $smtp; logtofile ($logdir.'/usermailer',"usermailer: mail written via net::sm +tp"); return 1; }
    The extra defined getout is probably redundant, but I know better than to mess with working code :) Most mail problems are to do with routing ime, half the time its getting out but not being routed. If you use a direct method like above you can send to the destination mailserver in one.
Re: Sending mail on a bad server...
by TriggerDunpoe (Novice) on Jun 28, 2004 at 01:35 UTC
    I uploaded perldiver to my client's server to find where sendmail was and it found
    /usr/bin/sendmail /usr/share/man/man8/sendmail.8.gz /usr/ports/mail/sendmail
    I did the whole Net::SMTP thing like what was suggested, but all it did was cause that subroutine to not load. =(

    Here's what I have now in sub "six" (6th page =P)
    open (MAIL, "|$mailprog -t") or &dienice("Can't access $mailprog!\n"); print MAIL "To: $FORM{'my_email'}\n"; print MAIL "Reply-to: $FORM{'email'}\n"; print MAIL "From: \"$FORM{'fname'} $FORM{'lname'}\" \<$FORM{'email +'}\>\n"; print MAIL "Subject: Transaction Notification\n\n"; print MAIL "$emailbody\n"; close(MAIL);
    In the main part of the code I have this: my $mailprog = '/usr/bin/sendmail';

    I forgot to mention that this still doesn't work.
Re: Sending mail on a bad server...
by andyf (Pilgrim) on Jun 29, 2004 at 14:02 UTC
    Are you remembering to use the modules? see perlfunc:use
    Have you downloaded the modules you want from CPAN?
Re: Sending mail on a bad server...
by TriggerDunpoe (Novice) on Jun 29, 2004 at 19:41 UTC
    Yup. His server didn't have the modules, so I had
    use lib '.';
    with all the module folders being in the same folder as the script, and then all of my use <module name> statements, and for some reason just having those in the code either made the subroutine not load or it would give a 500 error, even after all the modules and the script was set to 755 setting.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-19 17:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found