Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Cant send Email

by dbs (Sexton)
on May 27, 2011 at 13:33 UTC ( #906976=note: print w/replies, xml ) Need Help??


in reply to Cant send Email

I like this mail code, try it! Note, it has my own touch to it ...scalar @_ part I mean.
use MIME:Lite; sub _mailme($$$;$) { my $msg; if (scalar @_ == 3) { my ($to, $subject); ($to, $subject, $runlog) = @_; $msg = MIME::Lite->new( From => 'MAILER-DAEMON root', To => "$to", Subject => "$subject", Type => 'multipart/related' ); $msg->attach( Type =>'TEXT/html', Data =>"See attachment!" ); $msg->attach( Type => 'TEXT', Disposition => 'attachment', Path => "$runlog", Filename => "$runlog" ); } elsif (scalar @_ == 4) { my ($to, $subjct); ($to, $subject, $runlog, $mksysblog) = @_; $msg = MIME::Lite->new( From => 'MAILER-DAEMON root', To => "$to", Subject => "$subject", Type => 'multipart/related' ); $msg->attach( Type =>'TEXT/html', Data =>"See attachment!" ); $msg->attach( Type => 'TEXT', Disposition => 'attachment', Path => "$runlog", Filename => "$runlog" ); $msg->attach( Type => 'TEXT', Disposition => 'attachment', Path => "$mksysblog", Filename => "$mksysblog" ); } $msg->send; }

Replies are listed 'Best First'.
Re^2: Cant send Email
by TomDLux (Vicar) on May 27, 2011 at 15:28 UTC

    Besides the question of whether this solves the ability to sendmail on localhost, this code has serious duplication. I would read all four variables from @_, and then determine what to do based on whether the fourth variable has a value or not. Using prototypes for subroutines is deprecated, I would avoid it.

    use MIME:Lite; sub _mailme { my ($to, $subject, $runlog, $mksysblog) = @_; $msg = MIME::Lite->new( From => 'MAILER-DAEMON root', To => "$to", Subject => "$subject", Type => 'multipart/related' ); $msg->attach( Type =>'TEXT/html', Data =>"See attachment!" ); $msg->attach( Type => 'TEXT', Disposition => 'attachment', Path => "$runlog", Filename => "$runlog" ); if ( $mksysblog ) { $msg->attach( Type => 'TEXT', Disposition => 'attachment', Path => "$mksysblog", Filename => "$mksysblog" ); } $msg->send; }

    As Occam said: Entia non sunt multiplicanda praeter necessitatem.

Re^2: Cant send Email
by Mr. Muskrat (Canon) on May 27, 2011 at 15:16 UTC

    Question: How does this fix the issue posed by the OP?

    Answer: It doesn't. This will try to use the sendmail process on the system which will also fail given that there isn't a mail server configured on localhost!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2021-04-23 05:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?