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

attach PDF to email with javascript

Status
Not open for further replies.

Diggum1

Programmer
Oct 14, 2004
67
US
Hey guys, is it possible to attach a PDF to an email with javascript? I have a CD with an html page on it that will contain a bunch of PDFs. I would like to create a link for each PDF that says "email PDF" and this would launch their mail client (ala a mailto) but ALSO attach the PDF.

Can I do this?

Thanks
Rick
 
You can't do this using just HTML and javascript (client-side). You could do it server-side however (requiring ASP, JSP, PHP etc).

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
Found this on the web.
Code:
<html>
<head>
<SCRIPT language=javascript>
function MySub()
{document.mail.submit();}
</SCRIPT>
</head>
<BODY onload="MySub()">
<form name="mail" enctype="text/plain" method="get" action=mailto:?subject=Document&attachment="c:\test.doc">
</form> 
</body>
</html>

It purportedly had trouble with Outlook 2002 though what trouble was not specified.
I do not know how well it might work with other browsers and email clients either.

You can create a shortcut file with a cmd line like:
mailto:someone@somewhere.com&subject=File attached&attachment="c:\test.doc"

If you can execute the shortcut file then you would cause the launch of an email.

Look into HTA (HTML Applications) which can execute with client side permissions so you have access to client side resources.

You are however limiting yourself to the idea that the client is going to have email capability through a local email application.


Paranoid? ME?? WHO WANTS TO KNOW????
 
Unfortunately, since these PDFs will be distributed on CD, I don't have the luxury of a server-side language..

I also ran across the script below on the web, tho I'm not sure how to apply it. I used it as an OnClick event, but no luck.

this.mailDoc(true, "some...@somewhere.com", "this is for CC:", "this is for BCC:", "Subject of Email");

Thanks
Rick
 
I imagine that mailDoc thing is a snippet of some larger emailing function that the author built at some stage.

You could store a copy of the PDFs online (the latest version should you ever need to revise them) and serve them that way (click here to send this PDF to a friend). That way the owner has a full set of PDFs, can get updated PDFs, and can send them (via your PDF server) to their friends.

As long as bandwidth isn't a premium [smile]

Cheer,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
Yes, I think BabyJeffy is right about the mailDoc thing. It appears to be calling a function or component to handle the emailing and most likely has to have a server side piece.
The real problem is that you cannot rely on the client having javascript enabled or necessarily having a configured email application on the PC they are viewing the CD from. For that matter you cannot be certain they will even have internet access.

Why would you have the clients sending the PDF to someone else from the CD? Perhaps there is another approach but we have to understand the requirement first.
I can see someone with the CD wanting to view the PDF but why they would email it to someone else I do not understand.

As a modification to BabyJeffy's suggestion for having the PDFs hosted on a web server, perhaps a request to send an email with the attachment to someone else could be done the same way. Rather than relying on the client having email capability on that PC, if they have internet access it could pull up a web server page that allows entering the email address to submit the PDF file to.
This assumes of course that you have a web server to host the application and files of course.


Paranoid? ME?? WHO WANTS TO KNOW????
 
Thanks for the replies. The client keeps insisting it's possible, and I keep telling them that, from a CD, it's not. I really just wanted to make sure I wasn't overlooking something. They'll have to attach them manually.

Thanks

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top