Scott Overstreet wrote:

> I am having a problem with properly attaching a file to an email in a
> Perl script.  The file that I am attaching to each email is a simple tab
> delimited text file.  The problem is that the text file looks horrible
> because the columns don't line up evenly.  Because this is a "mass
> mailer" script that sends mail requesting that a bunch of people read
> the attachment and reply, it needs to be easy or people won't do
> it.  (It's a work thing...but where I work, people will simply ignore
> the message if there is anything more to it than double-clicking the
> attachment.)  So what I am trying to find out is how I can get a tab
> delimited excel spreadsheet into my emails; allowing the recipient to
> simply double-click the .xls file and pull up the information.
> 
> I have been dabbling with Spreadsheet::WriteExcel::Simple and toying
> with the MIME types set by MIME::Lite and I can't find the correct
> combination of the two.  What I typically end up with is a blah.xls file
> attached to the email and when you double-click it, you get the
> following error message:  "Unable to read file."
> 
> Any help/suggestions are greatly appreciated.  I apologize in advance if
> this is a newbie question.  I have only been doing Perl for about four
> months now.  Thanks.
> 
> -Scott
> 
> 
>      Here is sample code -- I won't paste the entire script to save you
> the pain of having to read it all.  Notice the two lines where I have
> commented like this: " #<--- I don't know what to put here. "

Your script didn't compile - always compile snippets before sending.

This works for me, but I have a modified MIME::Lite - if it fails for
you, email me for a possible code patch.  Make sure you make your changes
to addresses and mailserver and filename.

use strict;
use warnings;
use MIME::Lite;

my $filename = shift || 'fubar.xls';
my $recommended_filename = 'something.xls';
my $mime_type = 'application/vnd.ms-excel';
my $message = "Sending a .xls file for test\n";

my $from_address = '[EMAIL PROTECTED]';
my $to_address = '[EMAIL PROTECTED]';
my $subject = 'yadda yadda yah';
my $message_body = $message;

MIME::Lite->send('smtp', 'mymailserver.mynetwork.com', Timeout => 60);

# Create the initial text of the message

print "new msg\n";
my $msg = MIME::Lite->new(
   From => $from_address,
   To => $to_address,
   Subject => $subject,
   Data => $message_body,
) or die "Error creating MIME body: $!\n";

# Attach the file

print "attach file\n";
$msg->attach(
   Type => $mime_type,
   Path => $filename,
   Filename => $recommended_filename,
   Disposition => 'attachment',
) or die "Error attaching test file: $!\n";

print "send\n";
$msg->send;

__END__

-- 
  ,-/-  __      _  _         $Bill Luebkert    Mailto:[EMAIL PROTECTED]
 (_/   /  )    // //       DBE Collectibles    Mailto:[EMAIL PROTECTED]
  / ) /--<  o // //      Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_    http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to