my $email_params = { to => $email, from => 'robot@domain.ru', subject => encode_base64('Subject',''), text => 'Mail text', boundary => encode_base64($email,''), date => email_date(time);, msgid => encode_base64($email.$date,'').'@domain.ru', }; foreach my $d (sort keys %{$email_docs} ) { push @{ $email_params->{attachments}}, { FILEBASE64 => encode_base64($d->pdf), # binary FILENAME => $d->filename_pdf, FILETYPE => "application/pdf", } } my $tpl = new HTML::Template(filename => $template); $tpl->param($email_params); open(my $MAIL, "|/usr/local/bin/sudo /usr/sbin/sendmail -t"); print $MAIL $tpl->output; close ($MAIL);