Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

sending mail

by dangiles (Initiate)
on Dec 06, 2017 at 14:47 UTC ( [id://1205015]=perlquestion: print w/replies, xml ) Need Help??

dangiles has asked for the wisdom of the Perl Monks concerning the following question:

When I use mailx or sendmail (on RHEL 6.9, Perl v5.10.1) from within perl such as

qx( qq\cat $log | mailx -r $EMAIL_ADMIN -s "Exchange Backup Status $rp +tdate" $SEND_TO\ );
I receive the email in outlook with the following in the body of the message:
Message-ID: <5a27f1a0.VRRIyXDBT0l57yCy%xxx@yyy.com> User-Agent: Heirloom mailx 12.4 7/29/08 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit
If I run the command directly from the o/s, or have the perl code create a shell script with this command that then gets executed, this preamble does not appear.

Anyone know what may be going on here? I really don't want to use packages for such a simple operation.

Dan Giles, simple novice

Replies are listed 'Best First'.
Re: sending mail
by choroba (Cardinal) on Dec 06, 2017 at 17:07 UTC
    Nesting qq in qx doesn't work:
    $ perl -we 'qx(qq(ls))' sh: -c: line 0: syntax error near unexpected token `ls' sh: -c: line 0: `qq(ls)'

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
Re: sending mail
by haukex (Archbishop) on Dec 06, 2017 at 20:25 UTC

    Please have a look at my post here about the security issues with calling external commands. I really hope you've sanitized the variables you are interpolating into that shell command.

    I really don't want to use packages for such a simple operation.

    You will be doing yourself a huge favor by using a module like Email::Sender and the other Email::* modules by rjbs. Yes, even you can use CPAN! Example code.

    But if you really, really want to do it in pure Perl, then at least use a piped open instead of qx + cat:

    use warnings; use strict; use 5.008; my @cmd = ('mailx','-r',$EMAIL_ADMIN, '-s',"Exchange Backup Status $rptdate",$SEND_TO); die '@cmd must have more than one element' unless @cmd>1; open my $fh, '|-', @cmd or die $!; print $fh $mail_body; close $fh or die $! ? $! : $?;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1205015]
Approved by haukex
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-19 06:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found