473,326 Members | 2,114 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,326 software developers and data experts.

Sending mail from perl in unix

Hi ,
I am trying to send mail from unix perl.

I am using following code to send mail.
It is not triggering mail and also it is not giving any error.

please tell me any special settings are required or this program should be executed from special user with higher permission or something.

please tell me.


what changes i should bring into this program so that this program should work fine.


Expand|Select|Wrap|Line Numbers
  1. #!/usr/perl/bin/perl
  2. print "Content-type: text/html\n\n";
  3.  
  4. $title='Perl Mail demo';
  5. $to='shafi.mohammed@expt.com';
  6. $from= 'helpdesk.in@expt.com';
  7. $subject='YOUR SUBJECT';
  8.  
  9. open(MAIL, "|/usr/sbin/sendmail -t") || die "unable to open";
  10. print "hhhh ",<MAIL>,"\n";
  11.  
  12. ## Mail Header
  13. print MAIL "To: $to\n";
  14. print MAIL "From: $from\n";
  15. print MAIL "Subject: $subject\n\n";
  16. ## Mail Body
  17. print MAIL "This is a test message from Cyberciti.biz! You can write your mail body text here\n";
  18.  
  19. close(MAIL);


shafi
Feb 18 '08 #1
4 4249
eWish
971 Expert 512MB
The really only thing I see missing is the header for the email itself.

Expand|Select|Wrap|Line Numbers
  1. print MAIL "Content-type:text/plain; charset=iso-8859-1\n";
Here is a sample of one I did playing around with the some time ago.

Expand|Select|Wrap|Line Numbers
  1. #! /usr/bin/perl 
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. use CGI;
  7. use CGI::Carp qw/fatalsToBrowser/;
  8.  
  9. my $q = CGI->new;
  10.  
  11. print $q->header; 
  12. print $q->start_html(-title =>'Mysite.com'); 
  13.  
  14. my $mail_path         = '/usr/sbin/sendmail -i -t';
  15. my $email_to        = 'xxx@xxx.com';
  16. my $email_from        = 'xxx@xxx.com';
  17. my $email_subject    = 'Testing My Email';
  18. my $email_message     = qq~ 
  19. <pre>Hello $email_to,<br><br>
  20.  
  21. Thank you for $email_subject service.<br>  
  22. <a href="http://www.somesite.com">Some Site</a></pre>
  23. ~;
  24.  
  25. &send_email($email_to, $email_from, $email_subject, $email_message);
  26.  
  27. sub send_email{
  28.  
  29.     my ($to, $from, $subject, $message) = @_;
  30.  
  31.        open (my $MAIL, "|$mail_path") || print "Could Not Open Mail Program!";
  32.  
  33.            print $MAIL "Content-type:text/html; charset=iso-8859-1\n";
  34.            print $MAIL "To: $to\n";
  35.            print $MAIL "From: $from\n";
  36.            print $MAIL "Subject: $subject\n\n";
  37.            print $MAIL "$message\n\n";
  38.  
  39.    close ($MAIL);
  40.  
  41.    print 'Done.  Please check your email box';
  42.  
  43. print $q->end_html();
  44.  
  45. 1;
Hopefully it will help you! Also, please be sure to use the [CODE][/CODE] tags when posting code here. Thank you!

--Kevin
Feb 18 '08 #2
Hello here is the sample code with all the parameter filled still it is not working please let me know.


Expand|Select|Wrap|Line Numbers
  1. #!/opt/perl/bin/perl -w
  2.  
  3. my $send_to  = "To: ".'shafi.mohammed@capgemini.com'."\n";
  4.  
  5. my $subject="hi";
  6. my $content="how r u";
  7.  
  8. my $from='sandip.swain@capgemini.com';
  9. my $sendmail = "/usr/sbin/sendmail -t";
  10. open(SENDMAIL, "|$sendmail") or die "Cannot open $sendmail: $!";
  11. print SENDMAIL "Content-type:text/plain; charset=iso-8859-1\n";
  12. print SENDMAIL $subject;
  13. print SENDMAIL "From: $from\n";
  14. print SENDMAIL $send_to;
  15. print SENDMAIL "Content-type: text/plain\n\n";
  16. print SENDMAIL $content;
  17. close(SENDMAIL);
  18.  
  19. print "\nProcess completed\n";
Feb 19 '08 #3
Have you configure the ip address in the sendmail module...
Feb 19 '08 #4
try to run the sendmail command from unix prompt, then you will have some understanding on where exactly the problem lies, ie., unix config, or calling from perl

also you can try using mailx utility in Unix

-Nagendra
Feb 19 '08 #5

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

Similar topics

15
by: Sven Templin | last post by:
Hello all, our configuration is as following described: - OS: Windows 2000 - Apache server 1.3 - Php 3.8 - MS outlook client 2000 _and_ no SMTP server available in the whole intranet.
5
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # Suppose you want to spam your friend, and you have lots of # friends. The solution is to write a program to do it. After a gander # at python docs, one easily...
9
by: Leo Breebaart | last post by:
I am writing a utility in Python and I'd like to add a command-line option "--mailto <address>" that will cause an e-mail summary to be sent to <address> when the utility finishes running. My...
3
by: dpackwood | last post by:
Hello, I have two different scripts that do pretty much the same thing. The main perl script is on Windows. It runs and in the middle of it, it then calls out another perl script that then...
2
by: Kevin J Wholley | last post by:
How do I write a perl program to send mail from an xp box? specifically, I am writing a clearcase trigger that sends mail on a checkout. This functions perfectly from unix but I also need it to...
2
by: Michael | last post by:
I know that in order to send an e-mail using Perl there must be a '\' in front of the '@' symbol. For example department\@company.com. And it works. The problem that I am having is that we have...
7
by: tuspa | last post by:
Hi, I work on modelslim installed on unix server.It has its own prompt called vsim prompt.By using perl script,i call the vsim prompt ,I run what i want and then its stays in vsim promp.so,my...
6
by: cnsabar | last post by:
Hi., I am using following code to send sms through e-mail use Mail::Sendmail; %mail = (To => '10digitMobileNo@airtelkk.com', From => "mymail\@company.com", Message =>...
31
by: happyse27 | last post by:
Hi All, I am trying for weeks how to send email from windows pc, which from my gmail account to my hotmail account. Using net::smtp module sending email failed,Kindly assist. (for the item d it...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.