Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mail attachment shows blank but I know it's got content

Status
Not open for further replies.

marksa

Technical User
Sep 23, 2003
4
GB
I've got a mail script that tries to attach a text file to the mail. If I read the resultant mail in an html based mail reader it all seems ok. When I view it in Outlook there is an attachment of the correct size but the file
is empty.

The attach part of the script is

print MAIL<<EndOfAtt ;

--NextPart_000_000D_01C002C4.95399B80
Content-Type: text/plain;
name=&quot;$file&quot;
Content-Disposition: attachment;
filename=&quot;$file&quot;

EndOfAtt

Do I need some other parameters?

Thanks
 
Might work if you append &quot;.txt&quot; to the name of the attached file.

 
I tried that but same problem. The odd thing is that when I first open the attachment I can see the content for a millisecond - there must be something wrong with the header of the text file I guess.
 
What application are you opening the text file in? Notepad?

A text file doesn't have a header, so that shouldn't be it.

Have you tried converting the file to DOS format using unix2dos before sending it?

Annihilannic.
 
I've tried Notepad, Textpad and Dreamweaver
 
A web browser can read the file because that is the type of formatting you are doing.

Outlook may do better with the file if you append a &quot;.html&quot; to the file name.

Alternatively, when I send files from UNIX machines, I use uuencode:

uuencode /tmp/logfile logfile.txt | mailx -s &quot;log file&quot; fake@fake.com

I think I've seen this done in Perl before, i.e., redirecting to the MAIL file handle.
 
Do you mean save the attachment to the server as a .html? I've tried that and as a .txt.

Or do you mean just changing the script. Here's a cut down version of the script that I'm using for debugging

#!/usr/local/bin/perl
##############################################################
# SUCCESS.PL

$mailprog = '/usr/lib/sendmail';
$VSOemail = &quot;orders\@mydomain.com&quot;;
$printerEmail = &quot;orders\@mydomain.com

&sendVSOemail;

&writePage;

##############################################################
# Send Email to VSO

sub sendVSOemail {
$recipient = $VSOemail;
$mySubject = &quot;Online Order Notification&quot;;

open (MAIL, &quot;|$mailprog $recipient&quot;) || die &quot;Can't open $mailprog!\n&quot;;


print MAIL <<EndOfFail ;
From: orders\@theclient.com
To: $recipient
Subject: $mySubject
MIME-Version: 1.0
Content-Type: multipart/related; boundary=&quot;NextPart_000_000D_01C002C4.95399B80&quot;
X-Priority: 3 (Normal)

This is a multi-part message in MIME format.

--NextPart_000_000D_01C002C4.95399B80
Content-Type: text/plain; charset=&quot;iso-8859-1&quot;

Plain text

--NextPart_000_000D_01C002C4.95399B80
Content-Type: text/html; charset=&quot;iso-8859-1&quot;


<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<html>
<head>
</head>
<body bgcolor=&quot;#FFFFFF&quot;>
<hr size=&quot;1&quot; width=&quot;420&quot; align=&quot;left&quot; noshade>
<b><font size=&quot;3&quot; face=&quot;Arial, Helvetica, sans-serif&quot;>myTitle</font></b>
<hr size=&quot;1&quot; width=&quot;420&quot; align=&quot;left&quot; noshade>
<p>This is the HTML part</p>
EndOfFail
print MAIL &quot;</body></html>\n&quot;;

$file = 'cards/11111181.txt';

# does the next bit since the full script has just created this file and it needs permission
chomp($file);
chmod(0777, $file);

print MAIL<<EndOfAtt ;

--NextPart_000_000D_01C002C4.95399B80
Content-Type: text/plain; name=&quot;$file&quot;
Content-Disposition: attachment; filename=&quot;$file&quot;

EndOfAtt


open(FILE, $file) or die;
while( <FILE>) { print MAIL; };
close(FILE);

print MAIL &quot;--NextPart_000_000D_01C002C4.95399B80--&quot;;

close (MAIL);
}


##########################################################################################
#
# Output HTML
#
sub writePage
{

print <<EndOfFail ;
Content-type: text/html

<html>
<head>
<title>Finished Page</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>

</head>
<body>
<p>finished</p>
</body>
</html>

EndOfFail

exit;
}
#####################################

Thanks to all of you that have invested your mental energy in this one.



 
I think the problem is that you are telling Outlook to expect a file, but what you are actually giving it is the text from the file. In expecting a file, Outlook is looking for some form of file encoding which it does not find since you only send the text you're reading from the file.

The Perl forum may be a better place to have this question answered.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top