title: JavaMail Exception javax.mail.AuthenticationFailedException 534-5.7.9 Application-specific password required
body: <p>I want to send mail using JavaMailAPI</p>
  
  <p>I have done some coding but it is not working throwing Exception:-</p>
  
  <p>Message Sending Failedjavax.mail.AuthenticationFailedException: 534-5.7.9 Application-specific password required. </p>
  
  <pre><code>package com.appreciationcard.service;
  
  import java.util.Properties;
  
  import javax.mail.Message;
  import javax.mail.MessagingException;
  import javax.mail.PasswordAuthentication;
  import javax.mail.Session;
  import javax.mail.Transport;
  import javax.mail.internet.InternetAddress;
  import javax.mail.internet.MimeMessage;
  import com.appreciationcard.dao.DAOFactory;
  import com.appreciationcard.forms.ComposeForm;
  
  public class MailServiceImpl implements MailService {
  
  public boolean mailsent(ComposeForm composeForm) {
      String to = composeForm.getTo();
      String from = composeForm.getFrom();
      String cc = composeForm.getCc();
      String bcc = composeForm.getBcc();
      String subject = composeForm.getSubject();
      String messages = composeForm.getMessage();
      Properties props = new Properties();
      props.put("mail.smtp.host", "smtp.gmail.com");
      props.put("mail.smtp.auth", "true");
      props.put("mail.smtp.starttls.enable", true);
      props.put("mail.smtp.port", "587");
      props.put("mail.transport.protocol", "smtp");
      props.put("mail.debug", "true");
      System.out.println("Properties" + props);
      Session session = Session.getDefaultInstance(props,
              new javax.mail.Authenticator() {
                  protected PasswordAuthentication getPasswordAuthentication() {
                      return new PasswordAuthentication(
                              "tosudhansusekhar@gmail.com", "xxxx");
                  }
              });
      try {
          MimeMessage message = new MimeMessage(session);
          message.setFrom(new InternetAddress("dynamicmihir@gmail.com"));
          message.addRecipient(Message.RecipientType.TO, new InternetAddress(
                  to));
          message.setSubject(subject);
          message.setText(messages);
          Transport.send(message);
      } catch (MessagingException mex) {
          System.out.println("Message Sending Failed" + mex);
          mex.printStackTrace();
      } 
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I am getting Exception on server console </p>
  
  <p>Message Sending Failedjavax.mail.AuthenticationFailedException: 534-5.7.9 Application-specific password required.</p>
  
  <p>Learn more at 534 5.7.9 <a href="http://support.google.com/accounts/bin/answer.py?answer=185833" rel="noreferrer">http://support.google.com/accounts/bin/answer.py?answer=185833</a> o5sm11464195pdr.50 - gsmtp</p>
  
  <p><strong>Will Any one Kindly Help me out to solve this problem.</strong></p>