Email from PERL/ bash
I can not make this work:
I can send email from bash with this script:
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:
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??
ps Ubuntu 10 on the machine that I tried the script
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.
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"`;
unless you really need to understand
how e-mail sending mechanisms in Linux work, you can install the SendEmail script from:
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.
Thanks for comments and help,
I ended up using Net::SMTP and it works great.
ps to BMARX - I tried with ` but it did,t work
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.
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'");
|All times are GMT -5. The time now is 09:05 PM.|