Send Mail Using JavaScript With ElasticEmail

There were many requirements, such as sending mail using JavaScript and not using any REST API or other platform to create your own platform or server-side application.

we can use ElasticEmail to set up our own SMTP Hosting and send mail through it. So, let’s start by creating an ElasticEmail account, configuring the host, and sending mail with it.

Step 1: Go to the ElasticEmail

Step 2 :

Step 3: Choose Email API and click on the “Try For Free” Button and in the next page add the required all details or Sign Up with your google Account.

Step 4: After completing the Signup process, you will be presented with the Dashboard as shown below.

Creating a Hosting or SMTP Relay

Step 5: Now, go to Setting  and click on Create SMTP credential 

Step 6 : Enter Your UserName an click on create

Step 7 : When you click Create, you get a popup with the SMTP Details, as shown in the image.

Now that we’ve finished configuring our SMTP, we can write our business logic for JavaScript code to send email using our newly configured SMTP.

Mail.js

function sendMail()
       {
        Email.send({
            Host: "smtp.elasticemail.com",
            Username: "<Enter Your SMTP UserName>",
            Password: "<Enter Your SMTP Password>",
            To: '<Email TO send mail>',
            From: '<Email From which you are logged in to Elasticemail>', // put a real email address that is verified
            Port: '2525',
            Subject: "Hello",
            Body: "Hello",
        }).then(
            message => {
                alert("mail sent successfully");
                console.log(message);
            }
        );
    }

Mail.cshtml

<html>
  <head>
    <script src="https://smtpjs.com/v3/smtp.js"></script>
    <script src="Mail.js"></script>
  </head>
  <body>
    <form method="post">
      <input type="button" value="Send Email" onclick="sendEmail()"/>
    </form>
  </body>
</html>

After click Send Email Button I am getting the following mail inside my Gmail account.

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe

Select Categories