Expand|Select|Wrap|Line Numbers
- use strict;
- use warnings;
- use Mail::Sendmail;
- use MIME::QuotedPrint;
- use MIME::Base64;
- my $file1 = 'c:\test1.xls';
- my $file2 = 'c:\sample.zip';
- my $file3 = $file2 || $file1; # file to attach
- my %mail = ( To => "abc@yahoo.com",
- From => "def@yahoo.com",
- Cc => "hij@yahoo.com",
- Subject => "Two Attachments",
- smtp => 'mac.abc.com'
- );
- my $content;
- { local $/ = undef; # slurp file
- open IN, $file3 or die "Error opening $file3: $!";
- binmode IN; $content = <IN>;
- $mail{body} += encode_base64(<IN>);
- close IN;
- }
- my $boundary = "====" . time() . "====";
- $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
- my $message = encode_qp( $email_body );
- my $len = length $$mail{body};
- $mail{body} = <<EOD;
- $boundary
- Content-Type: text/plain; charset="iso-8859-1"
- Content-Transfer-Encoding: quoted-printable
- $message
- $boundary
- Content-Type: application/octet-stream; name="$file3"
- Content-Disposition: attachment; filename="$file3"
- Content-Transfer-Encoding: base64
- Content-Length: $len
- $mail{body}
- --$boundary
- Content-Type: application/vnd.ms-excel; name="$file3"
- Content-Disposition: attachment; filename="$file3"
- Content-Transfer-Encoding: base64
- Content-Length: $len
- $mail{body}
- $boundary--
- END_OF_BODY
- sendmail(%mail) or die $Mail::Sendmail::error;
- open(OUT, ">>$sendmail_log") or die "Cannot open LOG file $file3: $!";
- print OUT $Mail::Sendmail::log;
- print OUT "\n==============================================================================\n";
- close(OUT);