Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^4: Email Question

by btobin0 (Acolyte)
on Sep 24, 2015 at 20:49 UTC ( [id://1142950]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Email Question
in thread Email Question

Last Question.... Hopefully. close to the last line..
system ('mail -s "Test" testmail@server.com, < DailyReport_$d.txt');
I can send the email and I receive it but the subject does not show up. I have to me missing something simple.

Replies are listed 'Best First'.
Re^5: Email Question
by Laurent_R (Canon) on Sep 24, 2015 at 21:56 UTC
    Do you get a subject if you issue the same command at the shell prompt?

    But this might probably be more a Unix/Linux question than a Perl question. Not all mail utilities have exactly the same syntax, may be your should check yours.

    A possible alternative might be something along these lines (I haven't tested exactly that, but only something similar):

    my $subject = "Mail subject\n"; my $from = 'me@my_company.com\n'; my $cc = "whoever\@my_company.com\n"; open my $MAIL, "|/usr/sbin/sendmail -t" or die "... $!";; # Mail Header print $MAIL "To: addressee\@my_company.com\n"; print $MAIL "Cc: $cc"; print $MAIL "From: $from"; print $MAIL "Subject: $subject\n\n"; # Mail Body print $MAIL "\nThe accompanying message to be sent.\n\n"; my $stat_file = "$result_path/STAT.TXT"; open my $COUNT, "<", $stat_file or die "can't open $stat_file $!"; print $MAIL <$COUNT>; close $COUNT; print $MAIL "\n\n\n"; print $MAIL "Regards, \n"; print $MAIL "sender's signature, \n"; close $MAIL;
    Having said that, it might well be better to use a mail module, such as Mail::Send, Mail::Sendmail or some other (there are many, and I really can't advise one against any other).
Re^5: Email Question
by Corion (Patriarch) on Sep 24, 2015 at 21:14 UTC

    I don't know why the subject wouldn't be set, but there are problems with your snippet as shown:

    Single quotes will not interpolate. I suggest you split up the line as:

    my $cmd = 'mail -s "Test" testmail@server.com, < DailyReport_$d.txt'; print "Running [$cmd]\n"; system($cmd) == 0 or warn "Couldn't run [$cmd]: $! / $?";

    That way, you will see that $d does not interpolate in your command line.

    You should swap the quoting style and always quote all the components:

    my $cmd = "mail -s 'Test' 'testmail\@server.com' < 'DailyReport_$d.txt +'";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1142950]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (7)
As of 2024-04-25 08:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found