Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Help on emailing results

by Anonymous Monk
on Dec 18, 2003 at 19:03 UTC ( [id://315616]=perlquestion: print w/replies, xml ) Need Help??

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

Hey everyone,

I have written a perl script which rsh's into other unix boxes, kicks off another script, captures the result, and then displays the result onto the screen. I want to know how can I email that captured result. Can anyone show me an example of how it is done, or if someone could type in some code which they might have already developed.

Thanks

p.s I am very new to perl

Edited by footpad, 18 Dec 2003: Corrected use of HTML tags and applied minor proofreading.

Replies are listed 'Best First'.
Re: Help on emailing results
by thatguy (Parson) on Dec 18, 2003 at 19:25 UTC
    If you're running your script from a Unix box and you have Sendmail installed, you can always add this to your print:
    my $mailprogram = '/usr/sbin/sendmail'; # or path to your sendmail open (MAIL,"|$mailprogram -t"); print MAIL "To: toaddress\@example.com\n"; print MAIL "From:fromaddress\@example.com\n\n"; print MAIL $yourdata; #### Existing code that prints to the screen ### print "$yourdata\n"; #### End of print to screen ### close(MAIL);
    Hopefully this helps. I can't say it will or will not work for sure with your program since I haven't seen it.

    -phill
    Updated with missing \n that ysth spoted for 10 points.

Re: Help on emailing results
by b10m (Vicar) on Dec 18, 2003 at 19:32 UTC
    I don't want to sound like some "use anything but Perl"-guy ;), but the easiest solution would be to pipe the output to `mail` (mailx or Mail), since the output is already printed to the screen. Example:
    $ your_perl_script.pl | mail -s "Output from your_perl_script.pl" user +@domain.com

    Please note that I assume you run the script on some *NIX platform...

    Update: Linked to the wrong node - fixed

    --
    b10m
Re: Help on emailing results
by footpad (Abbot) on Dec 18, 2003 at 19:36 UTC

    Welcome to the Monastery. Be sure to check out some of the introductory materials for tips, especially those related to message formatting, good citizenship, and the like.

    As you might expect, sending email with Perl is a fairly common need and we have numerous examples and discussions available. For example, I typed "send email" into the Search box near the upper, left corner of the window and quickly found the following threads:

    Mind you, your final answer depends on the server you're saving your results file to and what's installed on it.

    Hopefully, though, one of the replies in the linked threads will help you find the specific answer you need.

    --f

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-03-29 15:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found