0

I am using node and express to serve pages rendered in embedded javascript. Wanted to include functionality of sending email through onclick() in my index.ejs file.

This is beginning of my index.ejs:

<!DOCTYPE html>
<html lang=""en">
<head>
<meta charset=""UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/public/assets/index.css">
<script src="https://smtpjs.com/v3/smtp.js"></script>
<script type="text/javascript">
function sendEmail() {
    console.log("I am at start of the sendEmail function");
  Email.send({
    Host: "smtp.elasticemail.com",
    Username : "m**************@gmail.com",
    Password : "***********************",
    To : '2***************@gmail.com',
    From : "m***************@gmail.com",
    Subject : "Test",
    Body : "Body",
    }).then(function (message) {
          alert("mail sent successfully")
}).catch(err => console.log("Email not sent"));
}
console.log("I am at the end of the sendEmail function");
</script>

A little down the code I activate the function using a Submit button in a form, and it gets activated. But no email is sent. No error either.

<button type="submit" onclick="sendEmail()">Submit</button>

I checked with the smtpjs guys and they asked me to verify my sending email, which I did. I had previously setup my smtp server with them.

What am I doing wrong? How can emails be sent when button is clicked? Do I need to replace ejs with simple html?

0 Answers0