You can use Mail::Sender
for sending emails with attachments.
I've just put simple example from my project for sending PDF file as
attachment.
See also Mail::Sender documentation for more details and examples.
my $body = 'This is a body of your message!';
# Define a hash with mail data
my $data_href = { to => 'recipients mails',
body => \$body,
+
ctype => 'text/plain',
smtp => 'your smtp server',
from => 'your email addr',
replyto => 'reply to addr',
+
subject => 'Your subject',
};
my $sender = new Mail::Sender() or die "Cannot create sender objec
+t!";
$sender->OpenMultipart( { %$data_href,
encoding => "quoted-printable",
debug => '/your/place/for/log fil
+e',
} );
warn "Error in mailing : $Mail::Sender::Error\n" unless ref $sende
+r;
$sender->Body( { msg => ${$data_href->{body}},
ctype => $data_href->{ctype},
encoding=> 'Base64',
} );
$sender->Attach( { file => 'your attach file',
description => 'Your attach description',
ctype => 'your attach file mime type',
encoding => 'Base64',
disposition => "attachment; file='your attach
+ file'; type='PDF'",
} );
$sender->Close;
if(defined $sender->{error}) {
warn "Error of sending mail to '$$data_href{to}': ".$sender->
+{error}."!!!"
} else { warn "Mail was sent to the '$$data_href{to}'!" }
Also, there is another way for building email messages - use MIME::Entity.
It's a part of MIME::tools library. Actually, I don't use this module, but I've seen
it in some application and heard that it's a good solution.
Hope I helped.
--------------------------------
SV* sv_bless(SV* sv, HV* stash);
|