What is EmailJs
gagecantrelle
Posted on August 18, 2024
Long ago in the past when computers weren’t created, people would write letters and send them to others. At the time, it would always be delivered by hand, which sometimes could be a problem since some messages need to be read immediately and not later. Other times these letters could be as simple as small talk, like “How are you today?” Luckily in 1965 at Mit when computers were around, Ray Tomlinson, a computer programmer, created the first email. This helped solve some of the problems of sending messages to people far away from you, but then a new problem arose. How do we let a computer send emails by itself? Luckily that is where EmailJs comes in and helps.
EmailJs is a free emailing application that allows you to create some code that will let you send an email. Without having to create one, giving you more time to do other things. Though it is free, there is a limit of 200 emails a month. You can upgrade your account, but it may cost a bit of money. Besides that, EmailJs was created by a software developer by the name of Eugene Shvets. It was launched in the year of 2014 on January 15. It was also popular with frameworks like React, angular, and others.
How do I use EmailJs?
First, we need to create an EmailJs account. You also need a regular email account to use EmailJs. Once you create an account, you need to create a service and an email template. The service is to tell what type of email service you're using, for example, Google Email. When you log in to Emailjs, go to the service tab then click the Add New Service. Once it is created it will show the service ID on its tab. It also shows it when you create it.
The email template is the same, just go to its tab on the left, then click Create New Template. Though it's different when creating it, when you click it it will give you a premade template. The template will look a bit weird but let me explain what those weird things are.
. double currly brackets represent data that is passed to the template
. this is like from_name to use from_name that passes to it to tell
who sent it
.(Devto don't like double currly brackets, it gives me a liquid
variable error. reference the image used)
. Cc or Carbon copy when set will send you a copy of an email that was
sent to someone
. good for testing purposes
. Bcc or Blind carbon copy is the same as Cc but instead of sending the
email copy to you it sent to another defined email account
. good for when working with multiple people
Let's start coding
To use EmailJs, you need to send a post request to an EmailJs link. The link will be provided in the EmailJs doc. Then provide an object with the service, template, public, and secret ID key for the request to work. The object will also take in a template_params which will hold information that the template will use, like the name of who sent the email and the message you are sending.
const object = {
service_id,
template_id,
user_id: emailjsPublicId,
token: emailjsSecretId,
tempate_params:{
from_name: 'me',
to_name: 'you',
message: 'hello'
}
}
axios.Post('https://api.emailjs.com/api/v1.0/send', object)
.then(()=>{console.log('send'))
Email is great for allowing users to quickly create and send emails quickly, saving some time for the user. It is also popular for automatically sending emails like sending emails with weekly/monthly information. Another thing would be automatically sending an email to a user with a receipt for what they buy online. I recommend looking into Windows.setInterval() and Cron for code to run on a set time frame, like running once per day. Simply put, EmailJs is great for the automatic and quick sending of emails. If a project you are working on will send emails, try EmailJs.
Links used:
https://www.theguardian.com/technology/2016/mar/07/email-ray-tomlinson-history#:~:text=The%20very%20first%20version%20of,logging%20in%20from%20remote%20terminals.
https://www.emailjs.com/doc
https://www.emailjs.com
Posted on August 18, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.