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

Hi All! I want to email only a specific addr however I have 2 To: fields.
sub mailme { my $message = shift; my $sub = shift; my $msg = MIME::Lite->new( From => 'MAILER-DAEMON root', To => 'UX Team <root>', To => 'operations@xxxx.com', Subject => "$sub", Type => 'multipart/related' ); $msg->attach( Type =>'TEXT', Data =>"See attachment!" ); $msg->attach( Type => 'TEXT', Disposition => 'attachment', Path => "$message", Filename => "$message" ); $msg->send; } mailme($log, $sub);
So before my job runs, I only want to email operations to notify them prior, so that they know. Can I use shift as I am with the subject? thanks!

Replies are listed 'Best First'.
Re: mime lite specific email
by ikegami (Patriarch) on Aug 04, 2010 at 16:08 UTC
    Is this what you want?
    sub mailme { my ($to, $sub, $file_path) = @_; my $msg = MIME::Lite->new( From => 'MAILER-DAEMON root', To => $to, Subject => $sub, Type => 'multipart/related', ); $msg->attach( Type => 'TEXT', Data => "See attachment!", ); $msg->attach( Type => 'TEXT', Disposition => 'attachment', Path => $file_path, ); $msg->send; } mailme('operations@xxxx.com', $sub, $log);
    • Added desired parameter.
    • Arranged order of arguments more logically.
    • Combined the three fetches from @_ into one statement.
    • Fixed indentation.
    • Removed useless stringification ("$foo"$foo).
    • Removed useless Filename argument (which wasn't even a file name).
Re: mime lite specific email
by zek152 (Pilgrim) on Aug 04, 2010 at 13:49 UTC

    You can easily test this yourself. Simply comment out the $msg->send; and insert print statements for $message and $sub.

    sub mailme { my $message = shift; my $sub = shift; print "Message = $message\n"; print "Sub = $sub\n"; } mailme("this is a message", "this is a subject"); #-OUTPUT- #Message = this is a message #Sub = this is a subject #

    So finally to answer the specific question, yes the shifts should work as intended.