?
Solved

problem - send excel file with sendmail

Posted on 2003-03-19
4
Medium Priority
?
418 Views
Last Modified: 2010-03-05
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
Comment
Question by:sputnik2002
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 48

Accepted Solution

by:
Tintin earned 300 total points
ID: 8169841

#!/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
 
LVL 1

Expert Comment

by:kmahida
ID: 8191916
use the module MIME::Lite as Tintin mentioned.

Thanks
-K
0
 
LVL 20

Expert Comment

by:jmcg
ID: 9699489
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

Introducing Priority Question

Increase expert visibility of your issues by participating in Priority Question, our latest feature for Premium and Team Account holders. Adjust the priority of your question to get emergent issues in front of subject-matter experts for help when you need it most.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question