0

Here is the code for sending a email:

use Email::MIME;
use IO::All;

my @parts = (
        Email::MIME->create(
                attributes => {
                        filename     => "report.xls",
                        content_type => "application/vnd.ms-excel",
                        encoding     => "base64",
                },
                body => "Body added as per the answer to this question"  #no effect
        ),
        Email::MIME->create(
                attributes => {
                        content_type => "text/plain",
                        charset      => "US-ASCII",
                        encoding     => "base64",
                },    
                body_str => "$body_of_message",
        ),
);

use Email::Send;

my $sender = Email::Send->new({mailer => 'SMTP'});
$sender->mailer_args([Host => 'localhost']);
$sender->send($email);

Now I am able to send mail and but report.xls is empty i.e. 0 bytes. It is present in my local directory and I am unable to understand why it is not being picked up as attachment. I have tried giving absolute path also but that does not work too.

Aman Deep Gautam
  • 8,091
  • 21
  • 74
  • 130

2 Answers2

2

It seems to be, you forget body parameter in first Email::MIME>create call (for attach). See example perldoc Email::MIME.

citrin
  • 725
  • 6
  • 9
0

You may want to look into Mail::SendEasy as it supports SMTP authentication and attachments.

If you insist on using Email::MIME - please note in the documentation it recommends using Email::Stuffer.

szabgab
  • 6,202
  • 11
  • 50
  • 64
falconspy
  • 750
  • 3
  • 8
  • 22