Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks, I rig up this script below which works fine, however I'm having trouble sending an attachment with it. I read the documentation provided in CPAN about Mail::Sender; but It is not specific as to which option should it be used with ATTACH. The script sends an attachment but it puts it on the email's body instead of creating an object. Do you know how to send an attachment with Mail::Sender as an object instead of putting the attachment into the email's body?? I appreciate if you could point me into the right direction.
use Mail::Sender; $sender = new Mail::Sender { smtp => 'smtp.server', from => 'email address', on_errors => undef, } or die "Can't create the Mail::Sender object: $Mail::S +ender::Error\n"; $sender->OpenMultipart({ to => 'emailaddress1, emailaddress2', cc => 'emailaddress3', subject => 'Log files.' }) or die "Can't open the message: $sender->{'error_msg'} +\n"; $sender->SendLineEnc("This is todays log files "); $sender->SendLineEnc("\nHI, J"); $sender->Attach( {description => 'Daily log', ctype => 'text/plain; charset="us-ascii"', encoding => '7bit', disposition => 'attachment; filename="textfile.txt"', file => 'textfile.txt' }); $sender->Close() or die "Failed to send the message: $sender->{'error_m +sg'}\n"; if ($@) { print "Error sending the email: $@\n"; } else { print "The mail was sent.\n"; }

Replies are listed 'Best First'.
Re: Attachment displays in email's body using Mail::Sender
by olivierp (Hermit) on Nov 27, 2004 at 09:31 UTC
    The documentation you read contains at least one example on sending a mail with an attachment.
    You will see that your script is not a multipart message, as it doesn't have a body part, but only an attachment part ... that is being considered as the body. Add the missing part, and it works.
    HTH
    --
    Olivier
      Nice