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

I am trying to get the hang of Perl and it's modules by making a simple web-based email client. I have completed the main page, and a page to retreive text email. Currently I am working on the page to send text email and have it 95% done. My problem is that it throws an error from the module I am using, specifically the open function.

<error message>
Died at C:/Perl/site/lib/Mail/Mailer.pm line 269.
</error message>

My code (taken almost verbatum from the Perl Cookbook):
my $SERVER = 'mail.domain.com'; ... sub send_text_message { # get our working variables my $to = $_[0]; my $from = $_[1]; my $subject = $_[2]; my $body = $_[3]; eval { my $mail = new Mail::Mailer ('smtp', server=>$SERVER); $mail->open({ From=>$from, To=>$to, Subject=>$subject, }) or die ("Can't send email headers: $!\n"); print $mail $body; $mail->close(); }; if($@) { print $page -> header(-type=> 'text/html', -charset=> 'utf8'), $page->p($@); return 0; } else { return 1; } }
Modules code:
sub open { my($self, $hdrs) = @_; my $exe = *$self->{Exe}; # || Carp::croak "$self->open: bad exe"; my $args = *$self->{Args}; # removed MO 20050331: destroyed the folding # _cleanup_hdrs($hdrs); my @to = $self->who_to($hdrs); $self->close; # just in case; # Fork and start a mailer (defined($exe) && open($self,"|-")) # <- line dying on || $self->exec($exe, $args, \@to) || die $!; # Set the headers $self->set_headers($hdrs); # return self (a FileHandle) ready to accept the body $self; }
I do not have a SMTP server on the localhost (I'm trying to get around that by using smtp setting). I have error handling to make sure the user is notified that the email wasn't sent. Any ideas why the open function can't send out an email?
life is a game... so have fun.

Replies are listed 'Best First'.
Re: Sending out text mail
by gube (Parson) on Oct 17, 2005 at 06:47 UTC

    Hi, try using this MIME::Lite module it's easy to Sending out text mail using sendmail or smtp.

    use MIME::Lite; ### Start with a simple text message: $msg = MIME::Lite->new( From =>'vijay@india.com', To =>'vijay@yahoo.co.in', Subject =>'A message with 2 parts...', Type =>'TEXT', Data =>"Here's the GIF file you wanted" ); $msg->send();
Re: Sending out text mail
by tirwhan (Abbot) on Oct 17, 2005 at 09:24 UTC

    When invoking new Mail::Mailer for smtp, the keyword needs to be "Server", not "server". See line 15 of Mail::Mailer::stmp.pm. So this will work:

    eval { my $mail = new Mail::Mailer ('smtp', Server=>$SERVER); $mail->open({ From=>$from, To=>$to, Subject=>$subject, }) or die ("Can't send email headers: $!\n"); print $mail $body; $mail->close(); };
Re: Sending out text mail
by Delusional (Beadle) on Oct 17, 2005 at 09:13 UTC
    Just to note something here, in most cases you can not send an email from a Windows system. On Linux, you can use sendmail (and most scripts do) to send mails, however, there is no such (default) possibility in Windows systems. You need additional software (such as blat) and/or Perl modules that handle everything needed. As I have not used any modules to send mail, and rely on sendmail to send messages (may or may not be the best way), I really can not explain why your script is failing, other then the possibility that its requireing sendmail or an additional plugin to actually function.

    Have you tried uploading (and setting permissions) to a linux system and running the script?
Re: Sending out text mail
by pajout (Curate) on Oct 17, 2005 at 09:28 UTC
Re: Sending out text mail
by terra incognita (Pilgrim) on Oct 17, 2005 at 22:54 UTC
    Another thing to be aware of is that most Anti-Virus programs now default to blocking you from automatically sending mail on a Windows machine. If you are running in a corporate enviroment this setting can usually be controlled by the network administrator, which will override any changes to the setting you make locally. In order to enable sending mail in this case you have to request having the policy turned off for your system. The only way around this if you can not get the policy turned off is to go through another supported mail client like Outlook via Win32::OLE.