# Austin Gilbert # 2006-08-01 # # An example of multiple MIME attachments using Perl::Sendmail # %mail = ( To => $addresses, From => $from, Subject => $subject, smtp => 'your SMTP server IP here' ); $boundary = "====" . time() . "===="; $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\""; $message = encode_qp( "$message" ); $boundary = '--' . $boundary; $mail{body} .= $boundary . "\r"; $mail{body} .= 'Content-Type: text/html; charset="iso-8859-1"' . "\r"; $mail{body} .= 'Content-Transfer-Encoding: quoted-printable' . "\r\r"; $mail{body} .= $message . "\r"; $mail{body} .= $boundary; # attach each file we have to the email... foreach $f ( keys( %files ) ) { #$boundary = "====" . time() . "===="; print "Attaching $f\n"; $mail{body} .= "\r"; $mail{body} .= $boundary; $mail{body} .= 'Content-Type: application/octet-stream; name="' . $f . '"' . "\r"; $mail{body} .= 'Content-Transfer-Encoding: base64' . "\r"; $mail{body} .= 'Content-Disposition: attachment; filename="' . $f . '"' . "\r\r"; $mail{body} .= $files{$f} . "\r"; $mail{body} .= $boundary; } #close the email body... $mail{body} .= '--' . "\r"; if( ! eval { sendmail( %mail ) or die( "$Mail::Sendmail::error" ) } ) { warn "$Mail::Sendmail::error\n"; } else { print "Message Sent\n"; }