i was wondering lately how i could send emails with only a front-end language like Javascript through Email as a Service apps like sendgrid or mandrill or so.
Sendgrid and mandrill have Curl APIS, so basically i can just do an AJAX post request to their API to send a mail but the thing is, i will have to put my API secret key in the JS file, this means it will be public... while it's supposed to be secret.
On those two apps, there's nothing in the docs concerning front-end use except having your own server which will use the API, but i'm currently on front-end based project. No server programming, the server only renders the assets that's all.
Do you guys know any method or apps of this kind to acheive this ? Thanks
The simplest way to send a message is to use QuickSend method of Smtp class (this method is static, it does not require you to create an instance of Smtp class). QuickSend method allows you to send e-mails out even if you do not have an SMTP relay server.
There are a few ways to send an email from your react application. This article will look at two of those methods: using the mailto HTML attribute, and using EmailJS. These methods will both work for frontend-only applications that are not supported by a backend server. Don't reinvent the wheel.
Can I send emails with JS or not? You can't send emails using JavaScript code alone due to lack of support for server sockets. For this, you need a server-side language that talks to the SMTP server. You can use JS in conjunction with a server script that will send emails from the browser based on your requests.
If you have a SendGrid account and an API key set as an environment variable, here is all the code you need to send an email in JavaScript: const sgMail = require ( '@sendgrid/mail'); sgMail. setApiKey ( process. env.
Even if it was possible to send e-mails directly using JavaScript (that is from users computer), the user would still have to connect to some SMTP server (like gmail.com), provide SMTP credentials, etc. This is normally handled on the server-side (in your application), which knows these credentials.
When the name JavaScript is used in the context of sending emails, Node.js is the first thing that comes to mind. We even blogged about how to send emails with Node.js. In this article, we want to change the perspective from the server-side to the client-side. Let’s figure out how you can use JS to send emails from the app that has no back-end.
The Twilio SendGrid API for sending email is a great solution to this problem. If you have a SendGrid account and an API key set as an environment variable, here is all the code you need to send an email in JavaScript: const sgMail = require ( '@sendgrid/mail'); sgMail. setApiKey ( process. env.
You can use FormSpree. Just provide the url in form action.
https://formspree.io/
Several suugestions
You could use a serverless architecture with AWS Lambda functions written in JavaScript.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With