Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Read a log file's content and send it in body of email

by kkurnala (Initiate)
on Mar 26, 2012 at 21:40 UTC ( #961761=perlquestion: print w/ replies, xml ) Need Help??
kkurnala has asked for the wisdom of the Perl Monks concerning the following question:

Hi PerlMonks I am a newbie into Perl. Trying to still learn nuts and bolts here. I am supposed to put together a perl script that would read a log file(text) and then e-mail it as body of e-mail using mime/sendmail. Can one of you guide me please !. Here is a piece of code i put together,but, not working though.
#!/usr/bin/perl -w use strict; use warnings; use Email::MIME::CreateHTML; use Email::Send; my $plain_text='text/plain'; my $sampletext; open(FH, "</apps/dryrun-merges/logs/dryrun-merge-report") || die("FAIL +ED to open dryrun merge report: $!"); #while(<FH>){ #$sampletext = $_; #} #close (FH); my $email = Email::MIME->create_html( header => [ From => 'kkurnala@wsgc.com', To => 'kkurnala@wsgc.com #,wso@wsgc.com,SJStep +hens@wsgc.com', Subject => 'Daily Dry-Run Merge Report - Test +Message', ], body => @lines, text_body => $plain_text ); my $sender = Email::Send->new({mailer => 'Sendmail'}); #$Email::sendmail = '/usr/sbin/sendmail'; #$sender->send($message) or die "Unable to send E-mail\n"; # $sender->mailer_args([Host => 'smtp.example.com']); $sender->send($email); print "About to send the E-mail, good-Bye!\n"; exit 0;
I am only getting a blank line like ---------- in the body of e-mail currently. The log file contains text like:
Summary of Conflicts:
Text Conflicts:
Tree Conflicts: Blah.. blah.. blah..

Comment on Read a log file's content and send it in body of email
Download Code
Re: Read a log file's content and send it in body of email
by tangent (Deacon) on Mar 26, 2012 at 22:58 UTC
    Where you say "body => @lines" there is nothing in @lines. To fix that insert at the top:
    my @lines = <FH>;
    However, unless your file is HTML your email will be garbled (e.g. it will not display linebreaks properly). If your file is not HTML then there is no need to use Email::MIME::CreateHTML, just use Email::Send:
    use strict; use warnings; use Email::Send; open(FH, "</apps/dryrun-merges/logs/dryrun-merge-report") or die("FAILED to open dryrun merge report: $!"); my @lines = <FH>; close(FH); my $message = <<'__MESSAGE__'; From: kkurnala@wsgc.com To: kkurnala@wsgc.com,wso@wsgc.com,SJStephens@wsgc.com Subject: Daily Dry-Run Merge Report - Test Message __MESSAGE__ $message .= join('',@lines); my $sender = Email::Send->new({mailer => 'Sendmail'}); my $result = $sender->send($message); print "$result\n";
      Thank you very much Tangent, Really Appreciate your Time ! Respect for the Community !! Your suggesstion did really help me. Thanks, Krishna.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (11)
As of 2014-11-27 11:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (184 votes), past polls