Batch-Batchrun

 view release on metacpan or  search on metacpan

lib/Batch/Batchrun/Mail.pm  view on Meta::CPAN

    {
        $mime->add("X-Priority" => "3");
        $mime->add("Priority" => "NORMAL");
    }


    #------------------------------------------------------------------------
    #
    # If Running on Windows and attachments then add them but with a full path.
    # If Running on Unix and attachments then add them.
    #
    #------------------------------------------------------------------------

    my($attachment);
    chomp($Mail{ATTACHMENTS});
    if ($Mail{ATTACHMENTS} ne '')
    {
        foreach $attachment (split(/,/,$Mail{ATTACHMENTS}))
        {
            my($type, $ending);
            $attachment =~ /.*\.(.+)$/;             # snag the ending
            $ending = $1;

            if (exists($ending_map{$ending}))       # Is it in our list?
            {
                $type = $ending_map{$ending};
            }
            else
            {
                $type = ['text/plain', '8bit'];     # default
            }

            # attach attachment with media type and encoding from the list
            # Note:  Windows requires full path
            attach $mime
                Type        => $type->[0],
                Encoding    => $type->[1],
                Path        => $attachment;
        }
    }


    #------------------------------------------------------------------------
    #
    # Send the mail message
    #
    #------------------------------------------------------------------------

    # Tell MIME::Lite to use Net::SMTP instead of sendmail (for UNIX)
        # Get Server list
        my ($server);
        my (@smtp_array);
        chomp($Mail{SMTPSERVER});

        # Grab server(s) and stick in an array
        if ($Mail{SMTPSERVER})
        {
            @smtp_array = (split(/,/,$Mail{SMTPSERVER}));
            foreach $server (@smtp_array)
            {
                if ( MIME::Lite->send('smtp', $server, Timeout => 20) )
                {
                    last;
                }
                else
                {
                    $failure = 1;
                }
            }
            if ( $failure )
            {
                die "Could not send mail message to \n '$Mail{SMTPSERVER}' \n";
            }

        }

    # Send mail
    $mime->send || die "you do not have mail!";
}
1;

__END__

=head1 NAME


Batch::Batchrun::Mail - send mail message for Batchrun


=head1 SYNOPSIS


use Batch::Batchrun::Mail;

mail( ADDRESS=>'test@somewhere.net',
     SUBJECT=>'Mail test',
     MESSAGE=>$somemsg,
     PRIORITY=>Urgent,
     FROM=>'user@host',
     CC=>'ccuser@host',
     SMTPSERVER=>'mailhost.net',
     ATTACHMENTS=>'d:\temp\attachment.text',
     HTML=>'htmltextmsg' );

=head1 DESCRIPTION

The C<mail> function provides a convenient way to send a mail message. Arguments are
passed using named parameters.  Each name is case insensitive. Of the several parameters
only ADDRESS is required.

This module uses MIME::LITE.  On unix systems the default is to use Sendmail to send the
message.  On Windows NT, Net::SMTP gets called by MIME::Lite. As of version 1.135 of
MIME::Lite there is a bug that does which causes CC addresses to be ignored when sending
messages via SMTP.  The author is aware of this and this will hopefully be fixed it in a
future release.

=head2 REQUIRED PARAMETERS

=over 4

=item B<ADDRESS>



( run in 2.000 seconds using v1.01-cache-2.11-cpan-302cb4679cc )