467,926 Members | 1,909 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,926 developers. It's quick & easy.

send email through a perl script.

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.
Aug 15 '08 #1
  • viewed: 6737
Share:
5 Replies
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.
Aug 15 '08 #2
KevinADC
Expert 2GB
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";
  4.  
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";
  4.  

Note the two \n\n after subject, that is necessary the way you are doing it.
Aug 15 '08 #3
numberwhun
Expert Mod 2GB
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
Aug 15 '08 #4
KevinADC
Expert 2GB
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.
Aug 15 '08 #5
eWish
Expert 512MB
In this thread I posted some code that would send an email with out the use of additional modules.

--Kevin
Aug 17 '08 #6

Post your reply

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

Similar topics

4 posts views Thread by julio Morales | last post: by
9 posts views Thread by Martin Foster | last post: by
3 posts views Thread by FLOTServer | last post: by
1 post views Thread by Balajisanthanakrishnan | last post: by
1 post views Thread by rahulthathoo | last post: by
2 posts views Thread by dandaman2007 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.