Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How to attach a file to a mail using JS?

    Dear all,
    I tried the following code but I can't get the mail with attachment.

    JS snippet:
    Code:
    function OpenMail()
    {
    window.location.href = 'mailto:rasw@op.pl?attachment="C:\\a.txt"';
    }
    HTML snippet:
    Code:
    <button onclick="OpenMail(); return false">Send</button>
    Please suggest a solution.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    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/fo...le.php/3461101

    The only reliable way to send an attachment is using a server-side language.
    http://www.finalwebsites.com/forums/...achment-script

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
    Last edited by Philip M; 05-23-2012 at 07:35 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,374
    Thanks
    11
    Thanked 592 Times in 572 Posts
    Quote Originally Posted by gandhikumar View Post
    Please suggest a solution.

    node.js's nodemailer package makes it trival to send attachments.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by rnd me View Post
    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.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •