Recently, I’ve been working on a project for a small construction company and the need for an automated email system presented itself. The company wanted to receive an automated email every time a customer filled out the “Contact Us” form on their website, so I turned to Google to figure out the best way to go about it.

Right off the bat, EmailJS seemed like the perfect candidate. It has good documentation and a really simple, easy-to-learn system. This tutorial will walk you through it.


Installing EmailJS

Before we jump into the code, you’ll want to create an EmailJS account. With your account, you’ll be able to create email templates and choose the email you want your automated emails to go to.

Next, install EmailJS on your project:

$ npm install emailjs-com --save

Then add the following code snippet to the head of your project:

	<script type="text/javascript"
	        src="https://cdn.jsdelivr.net/npm/emailjs-com@2/dist/email.min.js">
	</script>
	<script type="text/javascript">
	   (function(){
	      emailjs.init("YOUR_USER_ID");
	   })();
	</script>

To get your User ID, visit your EmailJS account page and click on the “API Keys” section.


Creating the Email Template

Now that you’ve got EmailJS installed and you’ve created an account, you’ll need to add an email service. I chose Gmail, but you can choose whichever service best suits your needs.

Next, we’ll create our email template. First, navigate to the templates page. There should already be a sample template, and you can choose to modify that one if you wish. If you’d like to create a new template from scratch, just click the “Create New Template” button.

Image for post

My template looked like this.

#reactjs #programming #emailjs #template #email #react

How to Use EmailJS for Automated Emails in React
28.85 GEEK