Solved

Auto sending a file as an attachment to an email

Posted on 2000-05-08
4
173 Views
Last Modified: 2013-12-25
Hi all,

What I need to do is get my hands on some kind of cgi script that allows a user to send themselves a file by clicking a link... I know it's a little obscure... why not just download it?  But hey, it's what the client wants.

I've seen this on another site, and it's done with a call to a cgi.

Thanks all,

mcneil
0
Comment
Question by:mcneil
  • 2
4 Comments
 

Expert Comment

by:hualian
ID: 2790705
I show you tips:

1. you can use redirect method.
    print "Location: somefile\n\n";
2. you need use encode the file and make a mail file like:
 
--bbtieappiqmaklud
Content-Type: application/octet-stream; name="5-67news.zip"
Content-Disposition: attachment; filename="youfile.zip"
Content-Transfer-Encoding: base64

UEsDBBQAAAAIAC2Ipyg4O0zCcqUAAMIgAQAMAAAAMjAwMDA1MDYudHh0rf3rc9v4
mSeKv1eV/gfXqdqqpGrS093pTjJ5dTKZmT1zzs4klWR3z7tTvZnemdSZTaaSzJmd
899QtGWJkmVeABAgCN4AEiBAECAAghItWzdLbluybEm27nT9ng8ewZQ7mdn9nUmn
0k2RwPfyfJ/77XvHzxT79epoXRx/97ufdcbf+PTjjz/+6OPPP/r4O98cLejtwoLY
--bbtieappiqmaklud--

how to encode base64:
follow is perl sub for encode base 64
sub encode_base64 ($;$) {
    my $res = "";
    my $eol = $_[1];
    $eol = "\n" unless defined $eol;
    pos($_[0]) = 0;                          # ensure start at the beginning
    while ($_[0] =~ /(.{1,45})/gs) {
        $res .= substr(pack('u', $1), 1);
        chop($res);
    }
    $res =~ tr|` -_|AA-Za-z0-9+/|;               # `# help emacs
    # fix padding at the end
    my $padding = (3 - length($_[0]) % 3) % 3;
    $res =~ s/.{$padding}$/'=' x $padding/e if $padding;
    # break encoded string into lines of no more than 76 characters each
    if (length $eol) {
        $res =~ s/(.{1,76})/$1$eol/g;
    }
    $res;
}

if you still have problem,please say.
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2793131
hualian,

you are using base64 encoding to send the file across.

but you need to realize that the end user/recipient must know how to use their email client to decode, using base 64, & then extract the file.

i know a vast majority of users (technical & non-technical) find it very difficult to do that!!.

i hope you have taken that into consideration in your solution.

0
 

Author Comment

by:mcneil
ID: 2793267
Sorry, guess I'm a little confused, or I wasn't clear enough.  What I'm looking to do is have a link on the web page that a person can click to email themselves a file.  This is done in two stages.  First the user clicks the appropriate file, and then gets a second page asking where he wants it sent to.

To see this in action, go to:http://www.national.com/pf/LM/LMV102.html#Datasheet and try clicking the "Recieve via email." You'll see what I mean.

I guess I'm hoping for a simple "prepackaged" cgi I can use to acheive this, as I've got little to no skills in that area.

Thanks for all your help.

mcneil
0
 
LVL 16

Accepted Solution

by:
maneshr earned 100 total points
ID: 2797951
i looked at the site you attached and here is the script that i have come up with.


====================LMV1202.html
<HTML>
<HEAD><TITLE>National P/N LMV102 - Fixed-Gain Amplifiers</TITLE>
<META NAME="description" CONTENT="LMV102 - Fixed-Gain Amplifiers">
</HEAD>
<BODY BGCOLOR="#FFFFFF" text="#000000" vlink="#660000" link="#003399" alink="#993300">
<TABLE BORDER=1>
<TR><TH>Title</TH><TH>Size<BR>(in Kbytes)</TH><TH>Date</TH>
<TH><BR>View Online</TH>
<TH><BR>Download</TH>
<TH><BR>Receive via Email</TH>
</TR>
<TR>
<TD>LMV101/102/105/110 Fixed-Gain Amplifiers</TD>
<TD>769 Kbytes</TD>
<TD>10-Dec-99</TD>
<TD><A HREF="/manesh/LMV101.pdf" TARGET="ViewPDF">View Online</A></TD>
<TD><A HREF="/manesh/LMV101.pdf">Download</A></TD>
<TD><A HREF="/cgi-bin/email_file.cgi?file=FLMV101.pdf">Receive via Email</A></TD>
</TR>
</TABLE>

==================email_file.cgi
#!/usr/local/bin/perl

use CGI;

$q=new CGI;

##  The file name
$file_name=$q->param('file');

print "Content-type: text/html\n\n";
if ($ENV{'REQUEST_METHOD'}=~ /^POST$/){ ##  User clicked on submit, after enter
ing a email id!!
  ##  Path where the file is stored
  $file_path="/www/docs/manesh/";
  ##  Full path and file name
  $full_name=$file_path.$file_name;

  ## Read the email id of the recipient.
  $email_id=$q->param('email');

  if ($email_id=~ /^\s+$/ || $email_id=~ /^$/){ ##  Dont accept empty email id!
!
    print "<B><FONT color=red>Please enter an email id!!</FONT></B><P>\n";
  }else{  ##  Email id is OK!!

    ##  Now send the file as an email attachment!!
    use SendMail;
    $sender  = "Manesh Rao <me\@this.com>";
    $subject = "Send an file as an attachment";
    $errorsto= $sender;
    $replyto = $sender;

    $sm = new SendMail("your.smtp.server");
    $sm->From($sender);
    $sm->To($email_id);
    $sm->ReplyTo($sender);
    $sm->ErrorsTo($errorsto);
    $sm->Subject($subject);

    ##  $full_name is the pathname of the attachment file, ...
    ##  ... this attachment file can sit in any directories.
    ##  Inside the email , only the filename is sent, ...
    ##  ... not with the whole pathname.
    $sm->Attach($full_name);

    print "<B>Mail has been sent to $email_id!!<B>\n";
    exit;
  }
}

print qq{
<form method=post action="$ENV{'SCRIPT_NAME'}">
<input type=hidden name=file value="$file_name">
<B>Enter the Email id of recipient</B> <input type=text name=email><P>
<input type=submit>
</form>
};
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In this tutorial I will aim to show you how simple is making a small application in WhizBase, how to add, remove and update data in the DB. I will make a small address book application where you can add, browse, update and remove addresses. I wi…
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now