Perl Send email | Newbie | | Join Date: Nov 2008
Posts: 1
| |
hi
Im new to Perl.
Im trying to write a program to send an e-mail via my cgi script. I tried various options - MIME::Lite, Sendmail, Mail::Sender, and none seem to work.
I get no error message in the Server Log file, but I dont receive an e-mail either. I suspect that it cant establish a connection to the SMTP server. Is there a way of knowing what communication happens with the SMTP server. The code I use is as below:
Thanks for your help.
Amy -
#!C:\Perl\bin\perl.exe
-
use CGI::Carp qw(fatalsToBrowser);
-
-
use Mail::Sender;
-
-
use Net::SMTP;
-
-
print "Content-type: text/html\n\n";
-
-
my $relay = "xxx.xxx.edu";
-
my $smtp = Net::SMTP->new($relay)
-
|| die "Can't open mail connection: $!";
-
my $to='xxx\@cs.xxx.edu';
-
my $from='xxx\@cs.xxx.edu';
-
-
$smtp->mail($from);
-
$smtp->to($to);
-
-
$smtp->data();
-
$smtp->datasend("To: $to\n");
-
$smtp->datasend("From: $from\n");
-
$smtp->datasend("Subject: $subject\n");
-
$smtp->datasend("\n");
-
-
foreach $body (@body) {
-
$smtp->datasend("$body\n");
-
}
-
-
$smtp->dataend();
-
$smtp->quit();
-
-
-
-
-
open my $DEBUG, ">> debugfile.txt"
-
or die "Can't open the debug file: $!\n";
-
-
$sender = new Mail::Sender
-
{smtp => 'mail.cs.xxx.edu', from => 'xxx@cs.xxx.edu'};
-
$sender->MailFile({to => 'xxx@cs.xxx.edu',
-
subject => 'Here is the file',
-
msg => "I'm sending you the list you wanted.",
-
debug => $DEBUG,
-
debug_level=>3,
-
authid=>'xxx',
-
authpwd=>'pwd'
-
});
-
$sender->SendEnc;
-
-
$sender->Close;
-
|  | Moderator | | Join Date: Oct 2006 Location: New York, United States of America
Posts: 3,428
| | | re: Perl Send email
Try Mail::Send; it's the module my professor suggests for e-mailing with Perl. Here's a short sample: - use Mail::Send;
-
my $mail = Mail::Send->new;
-
$mail->to('joe@example.com');
-
$mail->subject('Hey Joe');
-
my $fh = $mail->open();
-
print $fh "Hey Joe, what's up?";
-
$fh->close;
|  | Moderator | | Join Date: Jul 2007 Location: Arkansas
Posts: 900
| | | re: Perl Send email Mail::Sendmail is also a nice choice.
--Kevin
| | Familiar Sight | | Join Date: Sep 2008
Posts: 236
| | | re: Perl Send email
Hi Sirs,
I am using the codes above and it did not work. Used Email::send and not mail::send module as perl package manager did not have that.
Is it smtp or what problem.. Is there any sample? Thanks in advance.
Best Rgds,
Andrew -
-
#!/usr/bin/perl -w
-
#!c:/perl/bin/perl.exe
-
-
-
use Email::Send;
-
my $mail = Mail::Send->new;
-
$mail->to('joe@example.com');
-
$mail->subject('Hey Joe');
-
my $fh = $mail->open();
-
print $fh "Hey Joe, what's up?";
-
$fh->close;
-
-
Html error
========
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, admin@Andrew.solar and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
apache error log
============
[Thu Dec 11 14:13:52 2008] [error] [client 127.0.0.1] (OS 3)The system cannot find the path specified. : couldn't spawn child process: D:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/emailsend6.pl
apache access log
=============
127.0.0.1 - - [11/Dec/2008:14:13:51 +0800] "GET /cgi-bin/emailsend6.pl HTTP/1.1" 500 538
perl script testing in perl/bin
====================
C:\Perl\bin>perl -c d:\emailsend6.pl
d:\emailsend6.pl syntax OK
|  | Expert | | Join Date: Jan 2007 Location: Southern California USA
Posts: 4,091
| | | re: Perl Send email
wrong shebang line?
#!/usr/bin/perl -w
#!c:/perl/bin/perl.exe
the second one should be first, unless you actually have perl installed at usr/bin on your Windows box.
|  | Site Moderator | | Join Date: May 2007 Location: New Hampshire
Posts: 2,572
| | | re: Perl Send email Quote:
Originally Posted by happyse27 Hi Sirs,
I am using the codes above and it did not work. Used Email::send and not mail::send module as perl package manager did not have that.
Is it smtp or what problem.. Is there any sample? Thanks in advance.
Best Rgds,
Andrew -
-
#!/usr/bin/perl -w
-
#!c:/perl/bin/perl.exe
-
-
-
use Email::Send;
-
my $mail = Mail::Send->new;
-
$mail->to('joe@example.com');
-
$mail->subject('Hey Joe');
-
my $fh = $mail->open();
-
print $fh "Hey Joe, what's up?";
-
$fh->close;
-
-
Html error
========
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, admin@Andrew.solar and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
apache error log
============
[Thu Dec 11 14:13:52 2008] [error] [client 127.0.0.1] (OS 3)The system cannot find the path specified. : couldn't spawn child process: D:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/emailsend6.pl
apache access log
=============
127.0.0.1 - - [11/Dec/2008:14:13:51 +0800] "GET /cgi-bin/emailsend6.pl HTTP/1.1" 500 538
perl script testing in perl/bin
====================
C:\Perl\bin>perl -c d:\emailsend6.pl
d:\emailsend6.pl syntax OK You need to fix your code. You are calling one module and then specifying another in the constructor: -
use Email::Send;
-
my $mail = Mail::Send->new;
-
My suggestion is to read the Email::Send page at cpan.org and see if they have anything regarding logging.
Regards,
Jeff
| | Familiar Sight | | Join Date: Sep 2008
Posts: 236
| | | re: Perl Send email
Hi all,
This code didnt work either...
same problem of internal server error...
same logs.
kindly advise...
Thanks,
Andrew -
#!c:/perl/bin/perl.exe
-
-
-
-
use Mail::Sender::Easy qw(email);
-
-
-
-
email({
-
-
'from' => 'andrew@inovaventure.com',
-
-
'to' => 'happse@hotmail.com',
-
-
'cc' => 'your_pal@ddre.ss',
-
-
'subject' => 'Perl is great!',
-
-
'priority' => 2, # 1-5 high to low
-
-
'confirm' => 'delivery, reading',
-
-
'smtp' => '192.168.2.111',
-
-
'port' => 26,
-
-
'auth' => 'LOGIN',
-
-
'authid' => 'andrew',
-
-
'authpwd' => 'andrew2100',
-
-
'_text' => 'Hello *World* :)',
-
-
'_html' => 'Hello <b>World</b> <img src="cid:smile1" />',
-
-
'_attachments' => {
-
-
'smiley.gif' => {
-
-
'_disptype' => 'GIF Image',
-
-
'_inline' => 'smile1',
-
-
'description' => 'Smiley',
-
-
'ctype' => 'image/gif',
-
-
'file' => '/home/foo/images/smiley.gif',
-
-
},
-
-
'mydata.pdf' => {
-
-
'description' => 'Data Sheet',
-
-
'ctype' => 'application/pdf',
-
-
'msg' => $pdf_guts,
-
-
},
-
-
},
-
-
}) or die "email() failed: $@";
-
|  | Moderator | | Join Date: Jul 2007 Location: Arkansas
Posts: 900
| | | re: Perl Send email
You are missing some important data here. - use strict;
-
use warnings;
These are essential because the error you are saying is to vague. It could be many different things that are causing it. Without some error checking and syntax checking it is that much harder. Read this for some potential help for your problem.
--Mork
| | Familiar Sight | | Join Date: Sep 2008
Posts: 236
| | | re: Perl Send email
hi Sir,
The below code is working well as minimal codes... cheers...
Btw, how do I find free public smtp server since this is internal server ip with vpn??
Thanks again,
Andrew -
-
#!c:/perl/bin/perl.exe -w
-
-
use strict;
-
use warnings;
-
-
use Mail::Sender::Easy qw(email);
-
-
print "Content-type: text/plain\n\n";
-
-
-
email({
-
#from email address need to change
-
'from' => 'andrew@inova.com',
-
'to' => 'happse@hotmail.com',
-
'cc' => 'your_pal@ddre.ss',
-
'subject' => 'Perl is great!',
-
'priority' => 2, # 1-5 high to low
-
'confirm' => 'delivery, reading',
-
'smtp' => '192.168.2.111',
-
'port' => 25,
-
#'auth' => 'LOGIN',
-
'authid' => 'andrew@inovaventure.com',
-
'authpwd' => 'andrew2100',
-
'_text' => 'Hello *World* :)',
-
#'_html' => 'Hello <b>World</b> <img src="cid:smile1" />',
-
#'_attachments' => {
-
#'smiley.gif' => {
-
#'_disptype' => 'GIF Image',
-
#'_inline' => 'smile1',
-
#'description' => 'Smiley',
-
#'ctype' => 'image/gif',
-
#'file' => '/home/foo/images/smiley.gif',
-
#},
-
#'mydata.pdf' => {
-
#'description' => 'Data Sheet',
-
#'ctype' => 'application/pdf',
-
#'msg' => $pdf_guts,
-
#},
-
#},
-
}) or die "email() failed: $@";
-
-
| | Familiar Sight | | Join Date: Sep 2008
Posts: 236
| | | re: Perl Send email
Hi All,
This is the more complete codes with attachment sent successfully... Cheers...
Thanks,
Andrew -
#!c:/perl/bin/perl.exe -w
-
-
use strict;
-
use warnings;
-
-
use Mail::Sender::Easy qw(email);
-
-
print "Content-type: text/plain\n\n";
-
-
-
email({
-
'from' => 'andrew@inovaventure.com',
-
'to' => 'happse@hotmail.com',
-
'cc' => 'your_pal@ddre.ss',
-
'subject' => 'Perl is great!',
-
'priority' => 2, # 1-5 high to low
-
'confirm' => 'delivery, reading',
-
'smtp' => '192.168.2.111',
-
'port' => 25,
-
#'auth' => 'LOGIN',
-
'authid' => 'andrew',
-
'authpwd' => 'andrew2100',
-
'_text' => 'Hello *World5* :)',
-
'_html' => 'Hello <b>World</b> <img src="cid:smile1" />',
-
'_attachments' => {
-
'smiley.gif' => {
-
'_disptype' => 'GIF Image',
-
'_inline' => 'smile1',
-
'description' => 'Smiley',
-
'ctype' => 'image/gif',
-
'file' => 'D:/program files/Apache Software
-
-
Foundation/Apache2.2/htdocs\smiley.gif',
-
},
-
#'mydata.pdf' => {
-
#'description' => 'Data Sheet',
-
#'ctype' => 'application/pdf',
-
#'msg' => $pdf_guts,
-
#},
-
},
-
}) or die "email() failed: $@";
-
| | Familiar Sight | | Join Date: Sep 2008
Posts: 236
| | | re: Perl Send email
Hi all,
1) Btw, how do I find free public smtp server since this is internal server ip with vpn??
2) Is it possible to create html main page and use the perl scripts to activate the webpage respective iconed module functions? And eventually link back to the html again or Alternatively use perl to create the entire website?
Cheers...
Andrew
|  | Expert | | Join Date: Jan 2007 Location: Southern California USA
Posts: 4,091
| | | re: Perl Send email
Answer to #1 : google
I don't understand question #2, but you can use perl to create an entire website
| | Familiar Sight | | Join Date: Sep 2008
Posts: 236
| | | re: Perl Send email
Thanks Sir, that's what I needed to confirmed....
But using html as main page, and using perl as the CGI as the background module how to link back to html main page gracefully?
Cheers...
|  | Expert | | Join Date: Jan 2007 Location: Southern California USA
Posts: 4,091
| | | re: Perl Send email Quote:
But using html as main page, and using perl as the CGI as the background module how to link back to html main page gracefully?
Maybe you want to use SSI if you are going to use an HTML document but need dynamic content. Note that SSI has nothing to do with Perl so I will not answer any questions about SSI. Google for "SSI tutorial".
You can also use templating systems with perl to create dynamic websites but that will take you in a whole new direction.
| | Familiar Sight | | Join Date: Sep 2008
Posts: 236
| | | re: Perl Send email
Hi Kevin Sir,
Thanks... Any good websites with examples?? Went to a few, but the examples I could not understand how to integrate... Hands on: Simple templates with Perl - WhatPC?
Cheers...
Andrew
| | Familiar Sight | | Join Date: Sep 2008
Posts: 236
| | | re: Perl Send email
Hi Sirs,
Thanks! Slightly working now....
I found this html::template example and put the template1.tmpl and template1.pl in cgi-bin directory... please see the website reference below... Cheers...
Thanks,
Andrew
website reference : Introducing HTML::Template [CGI & Perl Tutorials]
template1.tmpl in D:\Program Files\Apache Software Foundation\Apache2.2\htdocs
=============================== -
<html>
-
<head>
-
<title>Template 1</title>
-
</head>
-
<body>
-
Today is <tmpl_var name=day>
-
</body>
-
</html>
-
template1.pl in D:\Program Files\Apache Software Foundation\Apache2.2\cgi-bin
=============================== -
-
#!c:/perl/bin/perl.exe -T
-
-
use CGI qw(:all);
-
use HTML::Template;
-
-
use POSIX;
-
print header;
-
my $template = HTML::Template->new(filename => 'template1.tmpl');
-
$template->param(day => strftime('%A', localtime()) );
-
print $template->output();
-
|  | Site Moderator | | Join Date: May 2007 Location: New Hampshire
Posts: 2,572
| | | re: Perl Send email
Andrew,
I hate to point this out now and am sorry that I did not catch it earlier, but you completely hijacked this thread. (IMHO)
I say this as we have not heard one bit from the original OP that started this thread and I am actually wondering if Amy has any questions still?
Next time, if you have questions and it will continue on as this did, it is always better to start a new thread and to reference the thread the code is from.
Regards,
Jeff
|  | Expert | | Join Date: Jul 2007
Posts: 169
| | | re: Perl Send email
As for creating HTML, or linking back gracefully...
Don't forget the CGI module, which comes standard with Perl. Active State, or UNIX version.
| | Familiar Sight | | Join Date: Sep 2008
Posts: 236
| | | re: Perl Send email
Hi Amy,
Sorry about that, cos I could not post new thread cos the website was under upgrading probably.
Hi Guys,
Thanks for the pointers again. Cheers...
Best Rgds,
Andrew
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,471 network members.
|