PDA

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



gandhikumar
05-23-2012, 06: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, 08: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.
http://www.finalwebsites.com/forums/topic/php-e-mail-attachment-script

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

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


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

felgall
05-24-2012, 09: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.