Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send mail with attachment using JS? [duplicate]

Can anybody tell me how to send mail with an attachment using JavaScript?

like image 923
Mausmee Rai Avatar asked Jun 30 '12 10:06

Mausmee Rai


3 Answers

You have two options to send email:

  1. Use server side implementation to send email, access it in Javascript via XMLHttpRequest
  2. Open the local email client from JavaScript and user can send email with pre-populated data.

     var link = "mailto:[email protected]"; 
     // In addition to this you can add subject or body as parameter . 
     // For e.g. 
     // "mailto:[email protected]?subject=test subject&body=my text"
     window.location.href = link;
    
like image 149
18bytes Avatar answered Sep 19 '22 09:09

18bytes


JavaScript is a client-side language. It is not concerned with (indeed, cannot) send e-mail, with or without an attachment. You'll need something server-side for that.

JavaScript can merely invoke the server-side script to send the e-mail, by requesting it, say, over AJAX, but it is not JavaScript which sends the e-mail.

This is akin to people mistakenly writing things like "I have some JavaScript which is getting some info from my database." It is not - it is requesting a server-side script which is getting the info from the database.

like image 22
Mitya Avatar answered Sep 20 '22 09:09

Mitya


With pure JavaScript, you can't send e-mails from the client. Remember, JavaScript is executed at the client (i. e. the user's browser).

like image 21
grimmi Avatar answered Sep 18 '22 09:09

grimmi