dimanche 26 juin 2016

Unable to send Mails using Java Mail API [Using Gmail]

I have used following code which was working fine in year 2014 but currently its not working.

Credentials used in this code are also correct.

public class SendMail 
{  
public void SendMailToTheUserWhoHaveForgotThePassword(String MailTo,String Password)
  {      
      String to = MailTo;  
      String from = "chatna06062016@gmail.com";
      final String username = "chatna06062016";     
      final String password = "xxxxxxxx";  

      String host = "smtp.gmail.com";  
      Properties props = new Properties();
      props.put("mail.smtp.auth", "true");
      props.put("mail.smtp.starttls.enable", "true"); 
      props.put("mail.smtp.host", host);   
      props.put("mail.smtp.port", "25");  
      Session session = Session.getInstance(props,new javax.mail.Authenticator() 
                    {             
                        protected PasswordAuthentication getPasswordAuthentication() 
                        {                
                            return new PasswordAuthentication(username, password);     
                        }          
                    }
                                            );  

      try 
      {   
          Message message = new MimeMessage(session);            
          message.setFrom(new InternetAddress(from));       
          message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to));        
          message.setSubject("FORGOTTEN PASSWORD"); 


          message.setText("Dear User The Password that you have forgotten is <b>"+Password +"</b>"+ 
                "This email is sended you by using JavaMailAPI "
                  + "HAVE A NICE DAY"
                  + "DO USE THIS SERVICE WHENEVER YOU NEED IT");  

    Transport.send(message);  
      System.out.println("Sent message successfully...."); 

      }
      catch (MessagingException e) { 
         throw new RuntimeException(e); 
      }

       }

} 

I have got email from google like this on the usage of the method used in above class.

Email Received from Google

Hi ChatNa,
Someone just tried to sign in to your Google Account chatna06062016@gmail.com from an app that doesn't meet modern security standards.
    Details:
Sunday, June 26, 2016 12:57 PM (India Standard Time)
Noida, Uttar Pradesh, India*
We strongly recommend that you use a secure app, like Gmail, to access your account. All apps made by Google meet these security standards. Using a less secure app, on the other hand, could leave your account vulnerable. Learn more.

Google stopped this sign-in attempt, but you should review your recently used devices:

What to do now unable to find out anything helpful anywhere.




Aucun commentaire:

Enregistrer un commentaire