Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Auto sending a file as an attachment to an email

Posted on 2000-05-08
4
Medium Priority
?
196 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
[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
  • 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 400 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

722 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