0

I'm making an SMTP-based mail sender. The code that I entered is -

    <script>
    function sendEmail(){
        Email.send({
            Host : "smtp.gmail.com",
            Username : 'davnit7607@davnitjsr.org',
            Password : "*************",
            To : 'davnit7607@davnitjsr.org',
            From : document.getElementById("email").value,
            Subject : "Contact",
        Body : "And this is the body"
}).then(
  message => alert(message)
);
    }
        
</script>
</body>
</html>

It's not working giving an error - The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required. Learn more at - Fix: Try a different SMTP server: https://elasticemail.com/account#/create-account?r=20b444a2-b3af-4eb8-bae7-911f6097521c

And- Mailbox name not allowed. The server response was: Envelope FROM 'hi@gmail.com' email address not allowed. Code

  • Please don't include images of your code. You can paste it in a code block in your post. – code Feb 22 '22 at 03:56

1 Answers1

0

Your errors...

The SMTP server requires a secure connection or the client was not authenticated.

  1. Are you running on HTTPS?
  2. You didn't provide proper authentication. You do realize you need your real email address (the username attribute; you're using Gmail, so you have to provide your Gmail address) and your real password to send emails from your account, right? (That includes the from field.) Gmail also has some extra complications. See this post on how to send emails from Gmail.

Mailbox name not allowed. The server response was: Envelope FROM 'hi@gmail.com' email address not allowed.

You tried to send an email from "hi@gmail.com". Do you think it will work? Let's pretend your email is bob@gmail.com. If what you attempted didn't result in an error, that means that I can send an email from your email without your permission! So no, that rightly shouldn't work.

All else aside, please don't try to send emails from the client-side. You realize that if you publish your app everyone can see your email address and password, right?

code
  • 5,690
  • 4
  • 17
  • 39
  • I have entered the secret token and moreover I have given the right email – Abhinav kumar Feb 22 '22 at 07:23
  • @Abhinavkumar but I doubt you have access to `hi@gmail.com`? (You tried to send an email from there, but you don't even know its password.) If you meant to send emails from `davnit7607@davnitjsr.org`, you have to change the host field to davnitjsr.org's respective SMTP host, and also, **the `from` field must be identical to the username (in most cases)**. – code Feb 22 '22 at 17:15