sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
lilly07's Avatar

send email through a perl script.


Question posted by: lilly07 (Member) on August 15th, 2008 08:25 AM
I am running a perl script under linux environment. I am looking for a possibility of sending mail to a set of pepole when something goes wrong. Is is possible to do? Thanks.
5 Answers Posted
lilly07's Avatar
lilly07 August 15th, 2008 08:52 AM
Member - 36 Posts
#2: Re: send email through a perl script.

I found a small example as below and tried.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. my $to='xyz@hotmail.com';
  4. my $from='xyz@hotmail.com';
  5. my $subject='Low Disk Space';
  6.  
  7. # send email using UNIX/Linux sendmail
  8. open(MAIL, "|/usr/sbin/sendmail -t");
  9. my $out = "testing";
  10.  
  11.  
  12. ## Mail Header
  13. print MAIL "To: $to\\n";
  14. print MAIL "From: $from\\n";
  15. print MAIL "Subject: $subject\\n";
  16.  
  17. ## Mail Body
  18. print MAIL $out;
  19.  
  20. close(MAIL);



When I execute the code, I get a message as below:
Expand|Select|Wrap|Line Numbers
  1. No recipient addresses found in header


How to resolve? Can't I use any public domains like hotmail etc.. or do I have to set up anything in my linux server. Please let me know. Thanks.
KevinADC's Avatar
KevinADC August 15th, 2008 10:17 AM
Expert - 3,612 Posts
#3: Re: send email through a perl script.

You need to remove the extra backslashes in these lines:

Expand|Select|Wrap|Line Numbers
  1. print MAIL "To: $to\\n";
  2. print MAIL "From: $from\\n";
  3. print MAIL "Subject: $subject\\n";


Should be:

Expand|Select|Wrap|Line Numbers
  1. print MAIL "To: $to\n";
  2. print MAIL "From: $from\n";
  3. print MAIL "Subject: $subject\n\n";



Note the two \n\n after subject, that is necessary the way you are doing it.
numberwhun's Avatar
numberwhun August 15th, 2008 01:31 PM
Forum Leader - 2,155 Posts
#4: Re: send email through a perl script.

In addition to the example that you found, you can also check out the Net::SMTP module from CPAN. Its also a good way to go.

Regards,

Jeff
KevinADC's Avatar
KevinADC August 15th, 2008 05:17 PM
Expert - 3,612 Posts
#5: Re: send email through a perl script.

Quote:
Originally Posted by numberwhun
In addition to the example that you found, you can also check out the Net::SMTP module from CPAN. Its also a good way to go.

Regards,

Jeff


I think they got that suggestion on Devshed.
eWish's Avatar
eWish August 17th, 2008 07:18 PM
Moderator - 815 Posts
#6: Re: send email through a perl script.

In this thread I posted some code that would send an email with out the use of additional modules.

--Kevin
Reply
Not the answer you were looking for? Post your question . . .
197,039 members ready to help you find a solution.
Join Bytes.com

What is Bytes?

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 197,039 network members.
Post your question now . . .
It's fast and it's free

Popular Articles

Top Perl Contributors