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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Message With Atatchment

Status
Not open for further replies.

paulbenn

Programmer
Jan 24, 2002
108
GB
Hi,

I am writing a script that email a file from a website however the file is on the Senders Computer and is being sent in for checking.

Please can someone help me??? Please

Below is my code that should handle the message

My Problem is I get a message but the attachment is not there, I but 2 Denug lines in the code one when the attachment routine is called (It Prints) and the second after the file is attached (It does not print?)

You can test the script at the file will email to the address you put in, so you can see my problem.

Sorry for the long message, but please help.

Code:
sub send_message
{

## Send File to poster Start
my @boundaryv = (0..9, 'A'..'F');
srand(time ^ $$);
for (my $i = 0; $i++ < 24;)
{
$boundary .= $boundaryv[rand(@boundaryv)];
}

open MAIL, &quot;|$mailprog -t&quot;;
print MAIL &quot;To: $tomail ($toname)\n&quot;;
print MAIL &quot;From: $email_address ($your_name)\n&quot;;
print MAIL &quot;MIME-Version: 1.0\n&quot;;
print MAIL &quot;Subject: $fileinfo\n&quot;;
print MAIL &quot;Content-Type: multipart/mixed; boundary=\&quot;------------$boundary\&quot;\n&quot;;
print MAIL &quot;\n&quot;;
print MAIL &quot;This is a multi-part message in MIME format.\n&quot;;
print MAIL &quot;--------------$boundary\n&quot;;
print MAIL &quot;Content-Type: text/html; charset=us-ascii\n&quot;;
print MAIL &quot;Content-Transfer-Encoding: 7bit\n\n&quot;;
print MAIL &quot;<b>Dear $toname,\n\n</b><br><br>\n&quot;;
print MAIL &quot;<br>Here is the file<br><br>File Attached: <b>$filename</b><br><br>\n&quot;;
print MAIL &quot;<br><br>\n&quot;;
#print MAIL &quot;--------------$boundary\n&quot;;

## Attach the file
&attach_files;

close INPUT;

print MAIL &quot;<br><b>End Attach file</b><br>\n&quot;;
print MAIL &quot;\n--------------$boundary--\n&quot;;
print MAIL &quot;\n&quot;;
close MAIL;

$status = &quot;Sent&quot;;
&okay_html;

}


sub attach_files {

$file=$attachment;
($ext) = $file =~ m,\.([^\.]*)$,;
$ext =~ tr,a-z,A-Z,;
$fext=&mimetype($ext);
print MAIL &quot;<br><b>Start Attach file</b><br>\n&quot;;
print MAIL &quot;--------------$boundary\n&quot;;
print MAIL &quot;Content-Type: $fext; name=\&quot;$filename\&quot;\n&quot;;
print MAIL &quot;Content-Transfer-Encoding: base64\n&quot;;
print MAIL &quot;Content-Disposition: attachment; filename=\&quot;$filename\&quot;\n\n&quot;;
&buf_type;
print MAIL &quot;Content-Type: text/html; charset=us-ascii\n&quot;;
print MAIL &quot;Content-Transfer-Encoding: 7bit\n\n&quot;;
print MAIL &quot;File: $filename Attached&quot;;
print MAIL &quot;--------------$boundary--\n&quot;;
#print MAIL &quot;--------------$boundary\n&quot;;
print MAIL &quot;<br><b>End Attach file</b><br>\n&quot;;
 }



sub buf_type {


my $buf2;
$/=0;
open INPUT, &quot;$file&quot;;
binmode INPUT if ($^O eq 'NT' or $^O eq 'MSWin32');
while(read(INPUT, $buf2, 60*57))
{
print MAIL &encode_base64($buf2);
}
}


sub encode_base64 #($)
{
my ($res, $eol, $padding) = (&quot;&quot;, &quot;\n&quot;, undef);

while (($_[0] =~ /(.{1,45})/gs))
{
$res .= substr(pack('u', $1), 1);
chop $res;
}

$res =~ tr#` -_#AA-Za-z0-9+/#;                               # ` help emacs
$padding = (3 - length($_[0]) % 3) % 3;                   # fix padding at the end

$res =~ s#.{$padding}$#'=' x $padding#e if $padding;    # pad eoedv data with ='s
$res =~ s#(.{1,76})#$1$eol#g if (length $eol);          # lines of at least 76 characters

return $res;
}
Kind Regards, Paul Benn

**** Never Giveup, keep trying, the answer is out there!!! ****
 
If there is anyway you could use perl, I have a SMALL quick snippet that would work.
 
It's worth a shot, Could you email it to paul@pbnet.co.uk

Cheers
Kind Regards, Paul Benn

**** Never Giveup, keep trying, the answer is out there!!! ****
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top