1

Here's my code that is not working:

print "To: ";  my $to=<>;  chomp $to;
print "From: ";  my $from=<>;  chomp $from;
print "Attach: "; my $attach=<>; chomp $attach;
print "Subject: "; my $subject=<>; chomp $subject;
print "Message: "; my $message=<>; chomp $message;

my $mail_fh = \*MAIL;
open $mail_fh, "uuencode $attach $attach |mailx -m -s \"$subject\" -r $from $to";
print $mail_fh $message;
close($mail_fh);

The mailx command works fine off the command line, but not in this Perl script context.

Any idea what I'm missing?


I suspect that this line's format/syntax:
open $mail_fh, "uuencode $attach $attach |mailx -m -s \"$subject\" -r $from $to";

is the culprit.

j0k
  • 22,600
  • 28
  • 79
  • 90
CheeseConQueso
  • 5,831
  • 29
  • 93
  • 126

3 Answers3

2

Do you really want to use external binaries for either the uuencode or the mailx bit? UUencode is almost trivial with pack.

brian d foy
  • 129,424
  • 31
  • 207
  • 592
  • Quite trivial - `my $encoded = pack 'u', $data;` The `u` template is a bit weird, and isn't explained well in perlfunc. There is an example in perlpacktut though: http://perldoc.perl.org/perlpacktut.html#Uuencoding – daotoad Mar 26 '10 at 05:12
2

You just need an extra | at the beginning:

open $mail_fh, "|uuencode $attach $attach |mailx -m -s \"$subject\" -r $from $to"; 
Gabe
  • 84,912
  • 12
  • 139
  • 238
1

There are other ways to send mail. See the How do I send mail? in perlfaq9.

brian d foy
  • 129,424
  • 31
  • 207
  • 592
ghostdog74
  • 327,991
  • 56
  • 259
  • 343