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

Mail::Mailer, strict, and From

by Anonymous Monk
on Jan 03, 2009 at 23:47 UTC ( [id://733964]=perlquestion: print w/replies, xml ) Need Help??

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

Not really a legal firm...anyway I just installed Mail::Mailer and ran into this:
Can't use string ("From") as a HASH ref while "strict refs" in use at +/usr/local/lib/perl5/site_perl/5.10.0/Mail/Mailer.pm line 180.
This is the documented method (such as it is) and I don't see how the "From" field can be avoided in sending an email, at least w/ Mail::Mailer since the option ($MTA->open(From=>$from ..., etc) is what it is.

I also just set up a new system and moved to perl 5.10 and noticed (because of this issue) that I apparently can no longer remove "use strict" (ie, the exact same error occurs). What's that about? Perhaps the module uses strict somewhere, but I doubt it because there are a few of these queries around the web (with no response).

Is there a better module for doing this (sending mail via a MTA) so that I don't have to learn all the little switches or whatever for postfix?

Replies are listed 'Best First'.
Re: Mail::Mailer, strict, and From
by sflitman (Hermit) on Jan 04, 2009 at 01:46 UTC
    I'd use MIME::Tools, it works really well. You just need to know where sendmail is located, postfix installs its own version of it which is compatible. Here's some code I use all the time:
    use strict; use vars qw/$cmdMail/; use LWP::MediaTypes qw(guess_media_type read_media_types); use MIME::Entity; BEGIN { $cmdMail='/usr/lib/sendmail'; # location of your sendmail read_media_types('/etc/mime.types'); # location of your mime.types + file } ... sub sendmail { # returns undef or error my ($from,$to,$subject,$body,@attachments)=@_; my $ret; my $top=build MIME::Entity From => $from, 'Reply-to' => $from, To => $to, Subject => $subject, Data => $body; if (@attachments) { for my $path (@attachments) { my $type=guess_media_type($path); $top->attach( Path => $path, Type => $type, Encoding => '-SUGGEST' ); } } $top->sync_headers(Length=>'COMPUTE') if @attachments; if (open(MAIL,"| $cmdMail -t -i")) { $top->print(\*MAIL); close MAIL; } else { $ret="Mail to $to failed: $!"; } $ret; } ... my $err=sendmail('server@wacky.com','programmer@wacky.com','Your turke +y is done!',"Come get some! Don't forget the beer!",'/home/programme +r/Pictures/beer.jpg'); die $err if $err; ...
    HTH,
    SSF
Re: Mail::Mailer, strict, and From
by Your Mother (Archbishop) on Jan 04, 2009 at 00:44 UTC

    I believe open in Mail::Mailer takes a hash ref, not a list of args. So $MTA->open(From=>$from ..., etc) should be $MTA->open({From=>$from ..., etc}). It's complaining because the first arg "From" isn't the hash ref it expects.

      Yep! Still ain't sure about that no more removing "use strict" tho.
Re: Mail::Mailer, strict, and From
by fmerges (Chaplain) on Jan 04, 2009 at 21:33 UTC

    Hi,

    I like to use Mail::Send interface instead

    Regards,

    fmerges at irc.freenode.net

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2025-11-12 20:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (68 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.