I do not know the Shell module, but the syntax error is in the call to $sh->mail: all text should be inside quotes, and you should (probably) use parentheses as well, for example: $sh->mail('-s', "hi", 'sharath@gmail.com')
Just for 'fun' I tried this code and, guess what? It ran the mail program. | [reply] [d/l] [select] |
That's strange. Just for fun, I used your idea and tried this. It works.
#!/usr/bin/perl
use strict;
use warnings;
use Shell qw(mail);
my $sh = Shell->new;
mail('-d');
| [reply] [d/l] |
Irrespective of the syntax problem, this approach isn't going to work anyway, because mail is not a shell built-in. In other words, the shell itself cannot send mail. So, unless you have some shell-external program or module installed that will do the actual sending, you won't have much luck sending mail that way...
| [reply] [d/l] |
| [reply] |
What I wanted to point out is that if there is no built-in called "mail", all a shell will do is try to invoke an external program of that name.
From the OP mentioning that there is no sendmail etc. installed (which mail would by default use as MTA), I figured that there most likely also is no working mail command available... In short, the Shell module alone then won't help with sending mail — which, as I understand, is what the OP was trying to achieve.
Update:
if it was (a built-in), it would be much less likely to work.
From a quick try it looks like the module has no problems running shell built-ins, as long as there are shell metacharacters in the arguments. Otherwise, the string is split and passed as separate arguments directly to the system call execve, thus bypassing the shell. (In other words, it seems the same rules as with system and friends apply.)
#!/usr/bin/perl
use Shell qw(echo);
echo "foo bar ;"; # with ";" --> uses 'echo' shell built-in
echo "foo bar"; # uses /bin/echo
(from strace -f output)
(echo "foo bar ;")
...
[pid 23888] execve("/bin/sh", ["sh", "-c", "echo foo bar ;"], ...
(echo "foo bar")
...
[pid 23889] execve("/bin/echo", ["echo", "foo", "bar"], ...
| [reply] [d/l] [select] |
As almut and cdarke say, simply invoking the 'mail' command via Perl isn't going to do anything if your machine isn't configured to send mail using the mail command. That is, if you aren't running SendMail, Postfix, or other mail server (even if the server is relaying to another mail server), the mail isn't going to go anywhere. Perl isn't going to provide additional functionality here, because it's just a scripted method of typing a command at a command prompt.
In addition, the use of the Shell package isn't recommended for production use by its own author, so you probably don't want to use this package to run shell commands.
If you do want to send mail usin Perl, but you don't want to run your own mail server, then I recommend the use of an SMTP server so that you can configure . Your Internet Service Provider should give information on how to use one (just get the host name, if user name and password is required, if TLS/SSL is required. If that fails too, then you can use Google as an SMTP server. Once you've done that, you can use Email::Simple to create a properly formatted mail that you can send with Net::SMTP
| [reply] |