I need to send emails in a front-end application that I'm using Vue.js, I would like to know if it's possible to send mail only with Javascript .. or do I need a server-side language for this? Thank you!
-
You cannot send email using front-end code. You either need to do server-side implementation or you can use services like sendgrid.com and mailgun.com, where they expose Rest APIs to do the work for you. – Shivaji Varma May 23 '18 at 03:38
-
technically speaking, a node.js backend would still be js – Daniel May 23 '18 at 05:11
-
You may want to take a look at [EmailJS](https://www.emailjs.com/?src=so), which allows sending email using pre-built templates directly from client side [disclosure - I'm one of the creators] – Sasha Jun 07 '18 at 16:23
5 Answers
No you can't send an email directly with javascript. But you can open user's mail client like this:
window.open('mailto:abc@example.com?subject=subject&body=body');
Where subject and body are optional parameters. I found it here.
- 417
- 3
- 14
All E-mails are sent through some kind of server so you would either need to use an API online or host a server where you could send and receive mail (Gmail's API requires you to host a server).
- 21
- 4
It is possible but not practical. You can use smtpjs.com. After you setup all the information, add these to your html:
HTML -> Head:
<script src="https://smtpjs.com/v2/smtp.js"></script>
JS
Email.send("from@you.com",
"to@them.com",
"This is a subject",
"this is the body",
"smtp.yourisp.com",
"username",
"password");
If you don't want to send your credentials over http, there's also a way to encrypt it as well.
You can encrypt your SMTP credentials, and lock it to a single domain, and pass a secure token instead of the credentials instead, for example:
Email.send("from@you.com",
"to@them.com",
"This is a subject",
"this is the body",
{token: "63cb3a19-2684-44fa-b76f-debf422d8b00"});
- 689
- 5
- 12
-
2Make sure you ask yourself "What's in it for smtpjs.com?" when you give them the keys to your mail server. – Quentin Mar 02 '20 at 13:20
No, you can't send emails from javascript or Html client-side because it generates the OTP page which is must be verified then it must be a server or use any third-party API by which you can send the email.
- 11
- 1
In theory no, you can not. However, there are options nowadays to send e-mail from the client side using third party services such as FormSpree and EmailJS.
- 7,095
- 3
- 24
- 37