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

Hi Monks, Following on from my post about sending emails without modules I’ve been trying very hard to get this to work for me and can’t so far, despite much reading of manuals, the net and the FAQs on here. I’m trying to send emails using a remote windows server that has Activestate Perl 5.10 installed on it. Mail::SendEasy is the module I’ve been advised to use by the support team (by email). Below I’ve listed four different ways that I’ve been advised to try to solve this issue and what errors they’re producing. Using the following code with Mail::SendEasy:-
#!/usr/bin/perl use CGI; use warnings; use strict; use CGI::Carp qw/fatalsToBrowser/; use Mail::SendEasy; my $query = new CGI; print $query->header(); print "it works";
it produces the error message:-
Can't locate Mail/SendEasy.pm in @INC (@INC contains: d:/perl/site/lib + d:/perl/lib .) at d:\domains\....etc
So despite being told it’s there I don’t seem to be able to call it. My alternative method suggested in a reply to my previous post was to use code like this using /usr/sbin/sendmail :-
#!/usr/bin/perl use CGI; use warnings; use strict; use CGI::Carp qw/fatalsToBrowser/; my $query = new CGI; print $query->header(); my $mailprog ="/usr/sbin/sendmail"; my $mailflags ="-t -n -oi"; my $recipient = 'recipient@domain.com'; my $msg_goes_here = "you're message"; open SENDMAIL, "| $mailprog $mailflags" or warn $!; print SENDMAIL "From: user\@domain.com\n"; print SENDMAIL "To: $recipient\n"; print SENDMAIL "Subject: testing 123\n\n"; print SENDMAIL $msg_goes_here; close SENDMAIL;
But this produces the error as follows:-
Send_Details.pl: Bad file descriptor at d:\domains\mysite.co.uk\wwwroo +t\cgi-bin\Send_Details.pl line 20 …etc
Which is referring to the open SENDMAIL line and I can’t figure out what’s wrong with this… Next I tried this suggestion from a reply to my previous post which was to use Net::SMTP code like this:-
use CGI; use warnings; use strict; use CGI::Carp qw/fatalsToBrowser/; use Net::SMTP; my $query = new CGI; print $query->header(); my $smtp = Net::SMTP->new( Host => 'mailhost.from.com', Hello => 'thishost.from.com' ); $smtp->mail('from@from.com'); $smtp->to('to@to.com'); $smtp->data('this is the text of the message'); $smtp->quit;
But this produces the error as follows:-
Can't load 'd:/perl/lib/auto/Socket/Socket.dll' for module Socket: loa +d_file:Access is denied at d:/perl/lib/XSLoader.pm line 64. at d:/perl/lib/Socket.pm line 412 Compilation failed in require at d:/perl/lib/Net/SMTP.pm line 13. BEGIN failed--compilation aborted at d:/perl/lib/Net/SMTP.pm line 13. Compilation failed in require at d:\domains\mysite.co.uk\wwwroot\cgi-b +in\Send_Details.pl line 10. BEGIN failed--compilation aborted at d:\domains\mysite.co.uk\wwwroot\c +gi-bin\Send_Details.pl line 10.
If I move the ‘use Net::SMTP’ line around as below:-
use CGI; use Net::SMTP; use warnings; use strict; use CGI::Carp qw/fatalsToBrowser/;
Then I get this error instead:-
CGI Error The specified CGI application misbehaved by not returning a complete s +et of HTTP headers.
Which generally I know what the error means but don’t know what’s wrong in this case. Finally I tried this suggestion from a reply to my previous post which was to install the modules locally on the bit of the server I can affect. This was a new concept to me so I’m probably missing something obvious here. I copied the module Mail::Sendmail from CPAN, renamed the file calling it ‘Dispatch’ and put it in a directory directly under the cgi-bin called ‘Postal’ and in the file renamed it ‘package Postal::Dispatch;’ and then called as below:-
#!/usr/bin/perl use CGI; use warnings; use strict; use CGI::Carp qw/fatalsToBrowser/; use Postal::Dispatch; my $query = new CGI; print $query->header(); print "it works";
And got the error:-
Can't locate Postal/Dispatch.pm in @INC (@INC contains: d:/perl/site/l +ib d:/perl/lib .) at d:\domains\mysite.co.uk\wwwroot\cgi-bin\Send_Det +ails.pl line 11. BEGIN failed--compilation aborted at d:\domains\mysite.co.uk\wwwroot\c +gi-bin\Send_Details.pl line 11.
If you’ve read this far thank you very much, I would really appreciate some pointing in the right direction here as it feels like I keep hitting objects that I can’t find the answer to how to get round them.

Replies are listed 'Best First'.
Re: Difficulty in sending mail with Activestate Perl 5.10 on a windows server
by Herkum (Parson) on Feb 02, 2009 at 15:45 UTC

    In the first iteration of your program you are using /usr/bin/sendmail, which is UNIX call, not a Windows call.

    I don't see why you would need CGI::Carp because you are not using CGI to send Email.

    Also, does the d:/perl/lib/auto/Socket/Socket.dll file exist? It says access denied which means to me that you don't have permissions.

    This is a simple email script that you can probably get to work if you install Mail-Sendmail on your system.

    use strict; use Mail::Sendmail; $Mail::Sendmail::mailcfg{smtp}=['mailhost.yourserver.com']; my %mail= ( To=>'herkum@yourserver.com,herkum@perl-example.com', From=>'you@perlmonks.org', Subject=>'Subject', Message=>'Body', ); Mail::Sendmail::sendmail(%mail) or die "Mail::Sendmail::error: '$Mail: +:Sendmail::error'";
Re: Difficulty in sending mail with Activestate Perl 5.10 on a windows server
by weismat (Friar) on Feb 02, 2009 at 14:47 UTC
Re: Difficulty in sending mail with Activestate Perl 5.10 on a windows server
by kennethk (Abbot) on Feb 02, 2009 at 15:52 UTC
    Yeah, what Herkum said. In addition, I looked through the Mail::SendEasy source, and it has no required dependencies that are not core modules, so even if you can't install it, you should be able to download the tar ball and run it locally.
Resolved: Difficulty in sending mail with Activestate Perl 5.10 on a windows server
by Stoney (Novice) on Feb 02, 2009 at 17:15 UTC
    Thanks for all your suggestions guys! What I had to do was 'use' the SendMail module like this:-
    use lib "Mail::SendEasy";
    This page was where I got the answer from :- http://perl.apache.org/docs/general/perl_reference/perl_reference.html#use____require____do_____INC_and__INC_Explained
      :: is illegal filename character on windows, so it was probably use lib 'D:/some/path';