Here is the code of the application. I have been trying to run this using eclipse IDE. I also added all the required java mail jar files namely
dsn.jar,imap.jar,mailapi.j
Try this steps
Step 2: Send mail from your device or application
If you connect using SSL or TLS, you can send mail to anyone with smtp.gmail.com.
Note: Before you start the configuration, we recommend you set up App passwords for the the desired account. Learn more at Sign in using App Passwords and Manage a user's security settings.
Connect to smtp.gmail.com on port 465, if you’re using SSL. (Connect on port 587 if you’re using TLS.) Sign in with a Google username and password for authentication to connect with SSL or TLS. Ensure that the username you use has cleared the CAPTCHA word verification test that appears when you first sign in.