Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 427
  • Last Modified:

problem - send excel file with sendmail

hello, i write a script with that create a excel file and send this by sendmail. i use for the sending no modul, i open a file handle by
open(SENDMAIL, "|/usr/lib/sendmail -oi -t")
and then i use print to write the data into the email

here is the code with that i read the excelfile, code it and send:

open(FILE,$file) || warn $!;
$content=<FILE>;
close(FILE);

$send_mail .= "Content-type: application/vnd.ms-excel; name=\"$filename\"; type=Unknown\n";
$send_mail .= "Content-transfer-encoding: BASE64\n";
$send_mail .= "Content-disposition: attachment\n";
$content= MIME::Base64::encode($content)
$send_mail .= $content;

open(SENDMAIL, "|/usr/lib/sendmail -oi -t")
or die "Can't fork for sendmail: $!\n";
print SENDMAIL $send_mail;
close(SENDMAIL);


the creation of the excelfile and the sending run without problems. but if i get the email and open the excelfile i get some error:

"[ file ] could not be accessed.  Sometimes the file or the storage location of the file is write protected, or the server, on which the document is stored, does not react any longer."

i hope someone can help me with this problem. and excuse me, my english is awfull
0
sputnik2002
Asked:
sputnik2002
1 Solution
 
TintinCommented:

#!/usr/bin/perl
use strict;
use MIME::Lite;

my $msg = MIME::Lite->new(
  From     => 'from@yourhost.com',
  To       => 'to@yourhost.com',
  Subject  => 'Attached Excel file',
  Type     => 'application/vnd.ms-excel',
  Path     => '/path/to/file.xls',
  Filename => "$filename"
);

$msg->send;
0
 
kmahidaCommented:
use the module MIME::Lite as Tintin mentioned.

Thanks
-K
0
 
jmcgOwnerCommented:
Nothing has happened on this question in over 7 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
accept answer by Tintin.

Please post any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now