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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.