View Full Version : How to attach a file to a mail using JS?

05-23-2012, 05:14 AM
Dear all,
I tried the following code but I can't get the mail with attachment.

JS snippet:

function OpenMail()
window.location.href = 'mailto:rasw@op.pl?attachment="C:\\a.txt"';

HTML snippet:

<button onclick="OpenMail(); return false">Send</button>

Please suggest a solution.

Philip M
05-23-2012, 07:24 AM
It is not possible to add an attachment to an email sent with mailto: using JavaScript. Doubtless this is a security feature.
The user may of course add an attachment manually in his email program.

See also: http://www.htmlgoodies.com/tutors/forms/article.php/3461101

The only reliable way to send an attachment is using a server-side language.

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

rnd me
05-24-2012, 04:11 AM
Please suggest a solution.

node.js's nodemailer package makes it trival to send attachments.

05-24-2012, 08:21 PM
node.js's nodemailer package makes it trival to send attachments.

Of course to be able to run the necessary JavaScript you'll need to have Node installed on the server.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum