Email file sent with perl Email :: Sender corrupted

I am trying to run a script that takes a text file, compresses it using Archive :: Zip, and sends the zip file as an attachment via smtp using Email :: Sender to create a mime message.

I can send txt files to perl without damage. I can send a file that perl fastens manually without damage. I cannot send a file with a manual encrypted file through perl.

I suspect my problem is that you are reading a zipped file or creating a MIME message. Here is the corresponding code, which is essentially the code from Email :: MIME syntax, where $ fileToSend is the path to the archived file.

Any ideas?

use strict; use warnings; use Email::MIME; use Email::Sender::Transport::SMTP; use Email::Sender::Simple qw(sendmail); use Archive::Zip qw( :ERROR_CODES :CONSTANTS); use IO::All; my $message = Email::MIME->create( header_str => [ From => $sender, To => $recipient, Subject => $subject, ], attributes => { filename => $filename, content_type => 'application/zip', disposition => 'attachment', name => $filename, }, body => io($fileToSend)->binary->all, #body => io($fileToSend)->all, ); 
+6
source share
2 answers

Finally found a problem. Adding this line did the trick.

 $message->encoding_set( 'base64' ); 
+5
source
 my $transport = Email::Sender::Transport::SMTP->new({ host => $smtpserver, port => $smtpport, sasl_username => $smtpuser, sasl_password => $smtppassword, ssl => 'starttls'}); Email::Stuffer->from(' a@a.com ') ->to(' b@b.com ') ->text_body('hello') ->attach_file ('zipfile') ->transport($transport) ->send(); 
0
source

All Articles