0

I have a requirement to send the a file(pdf/image) to specific users from my page. How can i achieve this with javascript? I do not want to hard-code the from mail address as i want to send the file from the user who logged on to the page.

Open and add the attachment to my default mail client is also acceptable for me. I have searched many sites but couldn't find an answer to the scenario. Anyone please help me through this.

Subin
  • 65
  • 2
  • 10
  • Use PHP. connect between the two with Ajax. Also, Possible Duplicate of [Send attachments with PHP Mail()?](https://stackoverflow.com/questions/12301358/send-attachments-with-php-mail) –  Jun 11 '17 at 08:07
  • You may want to take a look at [EmailJS](http://emailjs.com?src=so), which allows sending email using pre-built templates directly from Javascript, and also supports attachments. Using the user's from email is not really possible (unless you build something that connects to their own email account) but you can put their address in the "from name" and their email in the "reply to" address [disclaimer - I'm one of the creators] – Sasha Jun 11 '17 at 17:34
  • @Sasha I do not want to use something dependent on an internet connection as the application is an intranet application. I need a library that would help me sending emails with attachments. – Subin Jun 12 '17 at 06:52

1 Answers1

0

You will need to do a POST or GET ajax call to a server that has a kind of email sending technology like nodemailer from node.js or php.

First set up a node.js server. Then npm install nodemailer and configure it to your requirements.

In case you don't have access to a server, you can send emails directly within javascript using a platform like mailgun.com or mailchimp.com. Here is how you would do it with mailgun (that's what I use):

  1. Create an account in mailgun.com, you will get 10.000 emails free each month if you verify your domain else 300.

  2. Learn to use the api here mailgun send email api. First you will have to authenticate, and then you will be able to send emails.

Try it and let me know if you where able to send those emails. Remember that you don't need a server if you use the mailgun API or any other but I recommend you to set up a node.js server with nodemailer for more control.