smtp - How do I send multi-line output from Perl to /bin/mail? -
i have perl script prints multiple lines of output screen. need capture lines , either pipe them single piece of email ( /bin/mail ) or text file can send /bin mail in operation. actually, have figured out easy (dumb) way whereby use bash wrapper mailing bit. looks like,
#!/usr/bin/bash source /nethome/zog/.bash_profile cd /nethome/zog/bin/perl /nethome/zog/bin/perl/find_free_space.pl > text.file /bin/mail -s freespace@nj3 zog@geemail.com < text.file
i want using net::smtp smtp bit. above inelegant, least.
i saw this:
open(mail, "| /bin/mail -s freeports me\@geemail.com") || die "mail failed: $!\n"; print mail "this how goes."
on stackoverflow failed redirect stdout mail. i'm using:
$complete_output .= "\n"; "|/bin/mail -s freeports zog\@geeemail.com" || die "mail failed: $!\n";
i'm not sure if need see perl script in order help, it on pastebin. please let me know.
stdout isn't in play here. there forgot tell us? happened when printed mail
filehandle? did output make message? happens when send multiple lines mail
filehandle?
your code is:
"|/bin/mail -s freeports zog\@geeemail.com" || die "mail failed: $!\n";
that nothing. it's string, true value. alternation never die branch. happened when used first bit of code in question? write small example script see if can send mail , test until figure out. example, complete script tests problem:
#!perl use strict; use warnings; open $mail, '| /bin/mail -s freeports me@geemail.com'; print $mail "this test message $$ @ " . localtime() . "\n"; close $mail or die "the pipe failed!\n $?";
what happens when run that? happens when try same command command line?
why not use perl module (like 1 of email::* modules) instead of relying on external command? there's lot know interprocess communication, , think you're behind curve on that. module takes care of of details you, has nicer interface, , more flexible.
Comments
Post a Comment