LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 01-16-2011, 09:57 AM   #1
rkrasowski
LQ Newbie
 
Registered: Jan 2011
Posts: 2

Rep: Reputation: 0
Email from PERL/ bash


Hello,
I can not make this work:
I can send email from bash with this script:
#!/bin/bash
echo "Test message" | /usr/bin/mail -s "test2" "myEmail@yahoo.com"

When I am trying to run this in Perl using system function like this:
#!/usr/bin/perl
system("'Test message' | /usr/bin/mail -s 'test2' 'myEmail@yahoo.com');
I get message that program exited with code 0 , which is nice, but mail does not get to destination. Any idea what is wrong?? Can I do it in that way??
Thanks
Robert

ps Ubuntu 10 on the machine that I tried the script
 
Old 01-16-2011, 11:52 AM   #2
bmarx
Member
 
Registered: Dec 2004
Distribution: Slackware, Arch, FreeBSD
Posts: 202

Rep: Reputation: 34
What happens when you try executing that command from the command line (as opposed to a perl script)? Try enabling debugging in the command from the perl script to see what happens (--debug-level).

If you can not get that to work, you could always use the perl smtp interface.
http://search.cpan.org/~gbarr/libnet-1.22/Net/SMTP.pm

Also, have you tried just using backticks as opposed to the system() command? e.g.

$result = `echo "Test message" | /usr/bin/mail -s "test2" "myEmail@yahoo.com"`;
print $result;
 
Old 01-16-2011, 01:50 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,974
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
Quote:
Originally Posted by rkrasowski View Post
Hello,
I can not make this work:
I can send email from bash with this script:
#!/bin/bash
echo "Test message" | /usr/bin/mail -s "test2" "myEmail@yahoo.com"

When I am trying to run this in Perl using system function like this:
#!/usr/bin/perl
system("'Test message' | /usr/bin/mail -s 'test2' 'myEmail@yahoo.com');
I get message that program exited with code 0 , which is nice, but mail does not get to destination. Any idea what is wrong?? Can I do it in that way??
Thanks
Robert

ps Ubuntu 10 on the machine that I tried the script
Check your logs ... /var/log, and grep for the recipient.

Code:
grep myEmail@yahoo.com /var/log/*



Cheers,
Tink
 
Old 01-16-2011, 05:09 PM   #4
alizard
Member
 
Registered: Jan 2003
Posts: 56

Rep: Reputation: 15
unless you really need to understand

how e-mail sending mechanisms in Linux work, you can install the SendEmail script from:
http://caspian.dotconf.net/menu/Software/SendEmail/

or install it from the distro repositories:

from the command line:
$ sudo aptitude install sendemail

fill in the name / message (from file is OK) / SMTP server (TLS is OK)... and you're up and running.

Detailed instructions can be found at the URL or via the man(ual) file.

$ man sendemail

Good luck. Versions are also available for Winblows (98-XP, probably untested on Vista/W7) and OSX. A careful examination of the Linux script might tell you quite a lot about how e-mail sending works.
 
Old 01-16-2011, 08:29 PM   #5
rkrasowski
LQ Newbie
 
Registered: Jan 2011
Posts: 2

Original Poster
Rep: Reputation: 0
well,
Thanks for comments and help,
I ended up using Net::SMTP and it works great.
Thanks again
Robert

ps to BMARX - I tried with ` but it did,t work
 
Old 01-17-2011, 07:03 AM   #6
scook
LQ Newbie
 
Registered: Mar 2009
Posts: 4

Rep: Reputation: 0
Is the command you are using system with the same that works from the command line? I don't see the 'echo' in the text you show sent to system.
 
Old 01-17-2011, 09:05 AM   #7
zjoske
LQ Newbie
 
Registered: Dec 2009
Posts: 18

Rep: Reputation: 2
Hi

Your Perl statement is missing a quote (") at the end, before the semicolumn...
And ofcourse the echo statement is missing (as mentioned above)

Maybe that helps



system("echo 'Test message' | /usr/bin/mail -s 'test2' 'myEmail@yahoo.com'");

Quote:
Originally Posted by rkrasowski View Post
Hello,
I can not make this work:
I can send email from bash with this script:
#!/bin/bash
echo "Test message" | /usr/bin/mail -s "test2" "myEmail@yahoo.com"

When I am trying to run this in Perl using system function like this:
#!/usr/bin/perl
system("'Test message' | /usr/bin/mail -s 'test2' 'myEmail@yahoo.com');
I get message that program exited with code 0 , which is nice, but mail does not get to destination. Any idea what is wrong?? Can I do it in that way??
Thanks
Robert

ps Ubuntu 10 on the machine that I tried the script

Last edited by zjoske; 01-17-2011 at 09:10 AM. Reason: error in statement
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
passing variable from bash to perl in a bash script quadmore Programming 6 02-21-2011 04:11 AM
Perl VERP Email jack_weng Programming 1 11-29-2007 03:24 AM
send email using PERL just_a_kid Linux - Newbie 3 01-31-2007 07:11 PM
perl extract email subject winchester169 Linux - General 1 08-24-2006 04:55 AM
sending an email to a email address after a perl operation meluser Programming 9 04-07-2003 01:26 PM


All times are GMT -5. The time now is 04:06 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration