Search code examples
javascriptemailpassword-protection

Hide passwords that are in the .js file


I have a js file that sends emails like this:

Email.send ({
             Host: "smtp.gmail.com",
             Username: "mymail",
             Password: "mypassword",
             To: 'mymail',
             From: `$ {email}`,
             Subject: `Site, $ {name} invite a message`,
             Body: `$ {body} <br> $ {tel}`,
         })
         .then (function (message) {
             alert ("mail sent successfully")
         });

But my password is hardcode if someone inspect the code, can see it, how can I hide it?


Solution

  • Just don't do it this way as far as this code is not running on node.js server-side.

    Sending emails should be done on the server-side, dunno which language you are using so I'm going to paste below a list of useful classes from various frameworks/languages.

    1. PHP: https://www.php.net/manual/en/function.mail.php
    2. JAVA (Spring): https://docs.spring.io/spring-framework/docs/3.2.x/spring-framework-reference/html/mail.html
    3. C# (ASP.NET): https://learn.microsoft.com/en-us/aspnet/web-pages/overview/getting-started/11-adding-email-to-your-web-site

    And remember, never ever store passwords in plain text.