SMTP mails going to spam folder

I am using JavaScript to automate sending emails on my website, with SMTP and a gmail email address however the emails are sent directly to the receivers spam folder. Is there a way around this?

Here is my code:

   function sendEmail() {

      Email.send({
        Host: "smtp.gmail.com",
        Username: "[email protected]",
        Password: "pass",
        To: document.getElementById('email').value,
        From: "[email protected]",
        Subject: "Subject",
        Body: "hooray",
      })
        .then(function (message) {
          alert("mail sent successfully")
        });
    }