473,657 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sending mail from perl in unix

36 New Member
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 4263
eWish
971 Recognized Expert Contributor
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
mdshafi01
36 New Member
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
krishshan
5 New Member
Have you configure the ip address in the sendmail module...
Feb 19 '08 #4
npidaparthy
14 New Member
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
4299
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
1712
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 found the module for the job. # see http://python.org/doc/2.3.4/lib/SMTP-example.html # the code is a bit long with the command line, but the key lies at # the bottom four lines. The gist is this:
9
3115
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 first thought was to use smtplib.sendmail(), and basically this works like a charm, except that this function expects a valid 'sender' address as a parameter. Every single smtplib example I've found so far shows a hardcoded
3
6544
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 should run on a Unix box I have. Both scripts run ok, except for the part when Windows try's to call out the Unix script. I have it set up where the Unix is mapped through a drive letter and can drop stuff into the Unix box. It is going through another...
2
2202
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 run from xp for my clearcase users that use the clearcase client on the desk top
2
9951
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 many customers whom we need to direct towards their own personal online order form. For some reason when I try to place the '\' in front of the '@' symbol it does not work. For example person@isp.com. In order to send them an e-mail we need to
7
4117
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 question is how to switch to unix prompt from vsim prompt. the following is the code: #!/usr/intel/bin/perl $vlog = "vlog *.v < tt.txt"; print "$vlog"; open (PINGTEST, "vsim rwr0unit -f tcl_script -c |");
6
3167
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 => "SMS Server" );
31
12674
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 is working for normal email servers, but NOT with gmail server, I am very puzzled still!!) Codes(item c below) It keeps complaining and logs and codes are below. a) apache access logs --------------------------------- 127.0.0.1 - - "GET...
0
8737
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8509
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8610
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7345
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6174
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5636
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2735
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1967
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.