Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8989925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:22:52+00:00 2026-06-15T22:22:52+00:00

I have to fetch the password from MySQL database. That password is send to

  • 0

I have to fetch the password from MySQL database. That password is send to user valid email in Java using JDBC. How can I implement this?

Here is the code I am using:

public class Checkemail
{
    public String authentication( String Email ) {

        String retrievedUserName = "";
        String retrievedPassword = "";
        String status = "";

        try {
            Class.forName( "com.mysql.jdbc.Driver" );
            Connection con = DriverManager.getConnection( "jdbc:mysql://localhost:3306/xcart-432pro", "root", "" );
            PreparedStatement statement = con.prepareStatement( "SELECT * FROM xcart_customers WHERE email = '" + Email + "'" );
            ResultSet result = statement.executeQuery();

            while( result.next() ) {
                retrievedUserName = result.getString( "email" );
                retrievedPassword = result.getString("password");
            }

            if( retrievedUserName.equals( Email ) ) {
                status = "Valid Email";
            }

            else {
                status = "Invalid Email!!!";
            }
        }
        catch( Exception e ) {
            e.printStackTrace();
        }

        return status;
    }
}

Here I have checked the email is valid or invalid successfully.

How can I write the code for fetching the password and these password is send to email function?

EDIT:

Now i have changed the code like below:

    if(retrievedUserName.equals(Email)){
      status = "Valid Email";
      Properties props = new Properties();
        props.put("mail.smtp.host", "smtp.gmail.com");
         props.put("mail.smtp.socketFactory.port", "465");
         props.put("mail.smtp.socketFactory.class",
        "javax.net.ssl.SSLSocketFactory");
            props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.port", "465");

        Session session = Session.getDefaultInstance(props,
            new javax.mail.Authenticator() {
                  protected PasswordAuthentication getPasswordAuthentication() {
                        return new PasswordAuthentication("xxxxx@gmail.com","xxxx");
                        }
                    });

                    try {

                                Message message = new MimeMessage(session);
                            message.setFrom(new InternetAddress("krishnaveni.veeman@mercuryminds.com"));
                            message.setRecipients(Message.RecipientType.TO,
                                    InternetAddress.parse(Email));
                            message.setSubject("Testing Subject");
                        message.setText("Dear Friends This is your fassword," +
                                    retrievedPassword);

                    Transport.send(message);

                        System.out.println("Done");

                        } catch (MessagingException e) {
                            throw new RuntimeException(e);
                                }
                               }
                                  else{
                         status = "Invalid Email!!!";
                          }

                                }
                            catch(Exception e){
                               e.printStackTrace();
                                   }
                             return status;

                              }


                                } 

Here i have mentioned my gmail username and password on my code openly.

       Session session = Session.getDefaultInstance(props,
            new javax.mail.Authenticator() {
                  protected PasswordAuthentication getPasswordAuthentication() {
                        return new PasswordAuthentication("xxxxx@gmail.com","xxxx");
                        }
                    });

I have send mail w/o mention gmail username and password.please help me.how can i develop these.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:22:53+00:00Added an answer on June 15, 2026 at 10:22 pm

    You should use valid host.

    This may help you..

          String host = "smtp.gmail.com"; // Host for Gmail
          Properties props = System.getProperties();
          props.setProperty("mail.user", from);
          props.setProperty("mail.password", retrievedPassword);
          props.put("mail.smtp.host", host); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to fetch all the files from a folder and i am using
I have a MySQL DB and I fetch data from there via PowerPivot into
I have the following code to retrieve the password of a user from the
I have a simple MySQL 5 database that consists of id - Int -
I have a PHP search script that queries a MySQL database and then parses
I have a 'Database.php' that would handle database connections and would hand over mysql
I have a while loop running that is returning values from a MYSQL table.
I have a PHP keyword search script that searches a MySQL database and then
I have a form with PHP that saves a variable to a MySQL database.
I have a script that is supposed to read from the database and return

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.