send email with javascript

How to send email from JavaScript

To send email from JavaScript provide us easiness to not configure own server for this task, let consider a small static website having a contact form, generally for this form developer have to set up some server for receiving email from that contact form. Now it is easy to receive that email through JavaScript easily. So follow the article to learn

Email sending configuration on mailjs

First of all, go to and create an account, if you have already an account then sign in.

send email form javascript dotcode
Add new service

Then select the type you want to use, for this example I will select Gmail

send email from javascript dotcode
Connect account

This asks for authentication and allow the Gmail account to send emails for this service.

send email from javascript dotcode
Allow the account to send email from javascript

After allowing this the account will be connected with then click on create service, the service will be created and now it will be possible to send email from JavaScript.

Now as my service is created, now I will create an email template for sending emails through JavaScript.

Email sending service added

For creating a template go to the Email templates tab and click on create new, This will be the actual template for viewing an email that was received through JavaScript.

send email from javascript dotcode
Create email template

This will create a default template, if you want to make some changes you can.

In the Content tab, I put my email address which will be used as my email address for sending.

send email from javascript dotcode
Email template setup

Then navigate to the Setting tab and give some name to the template and save it.

Integration with own code

After saving the template now it is time to send an email through JavaScript. Click on Playground to see the code.

template create emailjs dotcode
Go to a playground and copy code

Then copy HTML from there to put in HTML and JavaScript to put in your code.

email js playground
Code for sending an email with JavaScript

There are methods available for different development environments. In

integration of email js
Different types of integration

For plain JavaScript follow the browser tab and paste the script into your code.

Here is the preview of my implementation of code

send email from javascript dotcode
Contact form to send email from JavaScript
success alert dotcode
Success email sending
send email from javascript dotcode
Email received

You can download my code which you can see in the above design from

The provide 200 email fee per month. That is more than enough for startups and small businesses.

So that was all about sending emails from JavaScript. Enjoy!

Watch video if have any doubt