473,414 Members | 1,686 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Perl Send email

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

Expand|Select|Wrap|Line Numbers
  1. #!C:\Perl\bin\perl.exe
  2. use CGI::Carp qw(fatalsToBrowser);
  3.  
  4.  use Mail::Sender;
  5.  
  6.  use Net::SMTP;
  7.  
  8.  print "Content-type: text/html\n\n";
  9.  
  10.  my $relay = "xxx.xxx.edu";
  11.  my $smtp = Net::SMTP->new($relay)
  12.     || die "Can't open mail connection: $!";
  13.     my $to='xxx\@cs.xxx.edu';
  14.     my $from='xxx\@cs.xxx.edu';
  15.  
  16.     $smtp->mail($from);
  17.         $smtp->to($to);
  18.  
  19.         $smtp->data();
  20.         $smtp->datasend("To: $to\n");
  21.         $smtp->datasend("From: $from\n");
  22.         $smtp->datasend("Subject: $subject\n");
  23.         $smtp->datasend("\n");
  24.  
  25.         foreach $body (@body) {
  26.             $smtp->datasend("$body\n");
  27.         }
  28.  
  29.         $smtp->dataend();
  30.     $smtp->quit();
  31.  
  32.  
  33.  
  34.  
  35.  open my $DEBUG, ">> debugfile.txt"
  36.                  or die "Can't open the debug file: $!\n";
  37.  
  38.  $sender = new Mail::Sender
  39.   {smtp => 'mail.cs.xxx.edu', from => 'xxx@cs.xxx.edu'};
  40.  $sender->MailFile({to => 'xxx@cs.xxx.edu',
  41.   subject => 'Here is the file',
  42.   msg => "I'm sending you the list you wanted.",
  43.   debug => $DEBUG,
  44.   debug_level=>3,
  45.   authid=>'xxx',
  46.   authpwd=>'pwd'
  47.  });
  48.    $sender->SendEnc;
  49.  
  50.   $sender->Close;
  51.  
Nov 19 '08 #1
18 8743
Ganon11
3,652 Expert 2GB
Try Mail::Send; it's the module my professor suggests for e-mailing with Perl. Here's a short sample:

Expand|Select|Wrap|Line Numbers
  1. use Mail::Send;
  2. my $mail = Mail::Send->new;
  3. $mail->to('joe@example.com');
  4. $mail->subject('Hey Joe');
  5. my $fh = $mail->open();
  6. print $fh "Hey Joe, what's up?";
  7. $fh->close;
Nov 19 '08 #2
eWish
971 Expert 512MB
Mail::Sendmail is also a nice choice.

--Kevin
Nov 20 '08 #3
happyse27
236 100+
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


Expand|Select|Wrap|Line Numbers
  1.  
  2. #!/usr/bin/perl -w
  3. #!c:/perl/bin/perl.exe
  4.  
  5.  
  6. use Email::Send; 
  7. my $mail = Mail::Send->new; 
  8. $mail->to('joe@example.com'); 
  9. $mail->subject('Hey Joe'); 
  10. my $fh = $mail->open(); 
  11. print $fh "Hey Joe, what's up?"; 
  12. $fh->close; 
  13.  
  14.  
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
Dec 11 '08 #4
KevinADC
4,059 Expert 2GB
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.
Dec 11 '08 #5
numberwhun
3,509 Expert Mod 2GB
@happyse27
You need to fix your code. You are calling one module and then specifying another in the constructor:

Expand|Select|Wrap|Line Numbers
  1. use Email::Send; 
  2. my $mail = Mail::Send->new; 
  3.  
My suggestion is to read the Email::Send page at cpan.org and see if they have anything regarding logging.

Regards,

Jeff
Dec 11 '08 #6
happyse27
236 100+
Hi all,

This code didnt work either...

same problem of internal server error...

same logs.

kindly advise...


Thanks,
Andrew

Expand|Select|Wrap|Line Numbers
  1. #!c:/perl/bin/perl.exe 
  2.  
  3.  
  4.  
  5.    use Mail::Sender::Easy qw(email);   
  6.  
  7.  
  8.  
  9.     email({
  10.  
  11.         'from'         => 'andrew@inovaventure.com',
  12.  
  13.         'to'           => 'happse@hotmail.com',
  14.  
  15.         'cc'           => 'your_pal@ddre.ss',
  16.  
  17.         'subject'      => 'Perl is great!',
  18.  
  19.         'priority'     => 2, # 1-5 high to low
  20.  
  21.         'confirm'      => 'delivery, reading',
  22.  
  23.         'smtp'         => '192.168.2.111',
  24.  
  25.         'port'         => 26,
  26.  
  27.         'auth'         => 'LOGIN',
  28.  
  29.         'authid'       => 'andrew',
  30.  
  31.         'authpwd'      => 'andrew2100',
  32.  
  33.         '_text'        => 'Hello *World* :)',    
  34.  
  35.         '_html'        => 'Hello <b>World</b> <img src="cid:smile1" />',
  36.  
  37.         '_attachments' => {
  38.  
  39.             'smiley.gif' => {
  40.  
  41.                 '_disptype'   => 'GIF Image',
  42.  
  43.                 '_inline'     => 'smile1',
  44.  
  45.                 'description' => 'Smiley',
  46.  
  47.                 'ctype'       => 'image/gif',    
  48.  
  49.                 'file'        => '/home/foo/images/smiley.gif',
  50.  
  51.             },
  52.  
  53.             'mydata.pdf' => {
  54.  
  55.                 'description' => 'Data Sheet',  
  56.  
  57.                 'ctype'       => 'application/pdf',
  58.  
  59.                 'msg'         => $pdf_guts,
  60.  
  61.             },
  62.  
  63.         },
  64.  
  65.     }) or die "email() failed: $@";
  66.  
Dec 12 '08 #7
eWish
971 Expert 512MB
You are missing some important data here.

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. 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
Dec 13 '08 #8
happyse27
236 100+
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

Expand|Select|Wrap|Line Numbers
  1.  
  2. #!c:/perl/bin/perl.exe -w 
  3.  
  4.    use strict; 
  5.    use warnings;  
  6.  
  7.    use Mail::Sender::Easy qw(email); 
  8.  
  9.     print "Content-type: text/plain\n\n";
  10.  
  11.  
  12.     email({
  13.         #from email address need to change
  14.         'from'         => 'andrew@inova.com',
  15.         'to'           => 'happse@hotmail.com',
  16.         'cc'           => 'your_pal@ddre.ss',
  17.         'subject'      => 'Perl is great!',
  18.         'priority'     => 2, # 1-5 high to low
  19.         'confirm'      => 'delivery, reading',
  20.         'smtp'         => '192.168.2.111',
  21.         'port'         => 25,
  22.         #'auth'         => 'LOGIN',
  23.         'authid'       => 'andrew@inovaventure.com',
  24.         'authpwd'      => 'andrew2100',
  25.         '_text'        => 'Hello *World* :)',    
  26.         #'_html'        => 'Hello <b>World</b> <img src="cid:smile1" />',
  27.         #'_attachments' => {
  28.             #'smiley.gif' => {
  29.                 #'_disptype'   => 'GIF Image',
  30.                 #'_inline'     => 'smile1',
  31.                 #'description' => 'Smiley',
  32.                 #'ctype'       => 'image/gif',    
  33.                 #'file'        => '/home/foo/images/smiley.gif',
  34.             #},
  35.             #'mydata.pdf' => {
  36.                 #'description' => 'Data Sheet',  
  37.                 #'ctype'       => 'application/pdf',
  38.                 #'msg'         => $pdf_guts,
  39.             #},
  40.         #},
  41.     }) or die "email() failed: $@";
  42.  
  43.  
Dec 14 '08 #9
happyse27
236 100+
Hi All,

This is the more complete codes with attachment sent successfully... Cheers...


Thanks,
Andrew

Expand|Select|Wrap|Line Numbers
  1. #!c:/perl/bin/perl.exe -w 
  2.  
  3.    use strict; 
  4.    use warnings;  
  5.  
  6.    use Mail::Sender::Easy qw(email); 
  7.  
  8.     print "Content-type: text/plain\n\n";
  9.  
  10.  
  11.     email({
  12.         'from'         => 'andrew@inovaventure.com',
  13.         'to'           => 'happse@hotmail.com',
  14.         'cc'           => 'your_pal@ddre.ss',
  15.         'subject'      => 'Perl is great!',
  16.         'priority'     => 2, # 1-5 high to low
  17.         'confirm'      => 'delivery, reading',
  18.         'smtp'         => '192.168.2.111',
  19.         'port'         => 25,
  20.         #'auth'         => 'LOGIN',
  21.         'authid'       => 'andrew',
  22.         'authpwd'      => 'andrew2100',
  23.         '_text'        => 'Hello *World5* :)',    
  24.         '_html'        => 'Hello <b>World</b> <img src="cid:smile1" />',
  25.         '_attachments' => {
  26.             'smiley.gif' => {
  27.                 '_disptype'   => 'GIF Image',
  28.                 '_inline'     => 'smile1',
  29.                 'description' => 'Smiley',
  30.                 'ctype'       => 'image/gif',    
  31.                 'file'        => 'D:/program files/Apache Software 
  32.  
  33. Foundation/Apache2.2/htdocs\smiley.gif',
  34.             },
  35.             #'mydata.pdf' => {
  36.                 #'description' => 'Data Sheet',  
  37.                 #'ctype'       => 'application/pdf',
  38.                 #'msg'         => $pdf_guts,
  39.             #},
  40.         },
  41.     }) or die "email() failed: $@";
  42.  
Dec 14 '08 #10
happyse27
236 100+
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
Dec 16 '08 #11
KevinADC
4,059 Expert 2GB
Answer to #1 : google

I don't understand question #2, but you can use perl to create an entire website
Dec 16 '08 #12
happyse27
236 100+
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...
Dec 17 '08 #13
KevinADC
4,059 Expert 2GB
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.
Dec 17 '08 #14
happyse27
236 100+
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
Dec 19 '08 #15
happyse27
236 100+
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
===============================
Expand|Select|Wrap|Line Numbers
  1. <html> 
  2. <head> 
  3.  <title>Template 1</title> 
  4. </head> 
  5. <body> 
  6. Today is <tmpl_var name=day> 
  7. </body> 
  8. </html>
  9.  
template1.pl in D:\Program Files\Apache Software Foundation\Apache2.2\cgi-bin
===============================
Expand|Select|Wrap|Line Numbers
  1.  
  2. #!c:/perl/bin/perl.exe -T
  3.  
  4. use CGI qw(:all); 
  5. use HTML::Template; 
  6.  
  7. use POSIX; 
  8. print header; 
  9. my $template = HTML::Template->new(filename => 'template1.tmpl'); 
  10. $template->param(day => strftime('%A', localtime()) ); 
  11. print $template->output();
  12.  
Dec 19 '08 #16
numberwhun
3,509 Expert Mod 2GB
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
Dec 19 '08 #17
Kelicula
176 Expert 100+
As for creating HTML, or linking back gracefully...
Don't forget the CGI module, which comes standard with Perl. Active State, or UNIX version.
Dec 22 '08 #18
happyse27
236 100+
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
Dec 25 '08 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: mhawkins19 | last post by:
I have a form built and on the onclick event I validate all of the fields and then if the form is ok, on the submit event I run a javascript function to set a cookie and download a file from the...
9
by: Bob Jones | last post by:
We have developed a commercial ASP.net application (personal nutrition management and tracking); we want to send smtp email from within it. For our development box, we use WinXP Pro, IIS 5.5,...
2
by: Ron | last post by:
hi guys, I am trying to send email using smtpMail. I can send emails inside the organization, but out of the organization I get an error "The server rejected one or more recipient addresses. The...
3
by: Gerard | last post by:
Hello I have created a windows service to monitor a database, it starts some checks when a timer elapses. The checks send emails depending on their findings. My issue is that when I created a...
2
by: ucasesoftware | last post by:
i start a process to send email via Outlook I have succes to build the email text, objet, sender... but i want to automate the "send"... i don't want my users to click on Send email button......
3
by: =?Utf-8?B?SHVnaA==?= | last post by:
Hi There, I use follow code to send email inside VB.NET 2005. It does not work well. Error message of "Failure sending email" would occue. However, email was sent out sometimes. I am confused...
16
by: =?Utf-8?B?Q2hlZg==?= | last post by:
I can use outlook2003 to send email,but I cann't use this code below to send email. Please help me to test this code and instruct me how to solve this problem in detail. software...
7
by: Cecil1984 | last post by:
hi guys, could any one help me how to write perl script to send email in unix system. thank you for any helping.
4
by: shailendra deshpande | last post by:
right now i have only pain html page.and i want to send email through it using javascript plz. anybody tell me how to send email from plain html page using javascript. thanks in advance ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.