title: Mail : com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.1 Authentication required
body: <p>I am trying to send an Email from my Java Application to any particular email address. I am using JavaMail API but Unfortunately i am getting SMTPSendFailedException error. Can any body tell me where i am doing a mistake. Here is my code</p>
  <pre><code>    Properties properties = new Properties();
      properties.put(&quot;mail.smtp.host&quot;, &quot;plus.smtp.mail.yahoo.com&quot;);
      properties.put(&quot;mail.smtp.port&quot;, &quot;587&quot;);
      properties.put(&quot;mail.smtp.starttls.enable&quot;, &quot;true&quot;);
      properties.put(&quot;mail.smtp.user&quot;, emailId);
      properties.put(&quot;mail.smtp.password&quot;, password);
  
      Session emailSession = Session.getDefaultInstance(properties,
              new Authenticator() {
                  protected PasswordAuthentication getPasswordAuthentication() {
                      return new PasswordAuthentication(emailId,password);
                  }
              });
      emailSession.setDebug(true);
  
      try {
          MimeMessage message = new MimeMessage(emailSession);
          message.setFrom(new InternetAddress(from));
          message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
          message.setSubject(&quot;Ping&quot;);
          message.setText(&quot;Hello, this is example of sending email  &quot;);
  
          // Send message
          Transport.send(message);
          System.out.println(&quot;message sent successfully....&quot;);
  
      } catch (MessagingException e) {
          throw new RuntimeException(e);
      }
  </code></pre>
  <p><strong>when I ran this code I got :</strong></p>
  <pre><code>DEBUG: setDebug: JavaMail version 1.4.7
  DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
  DEBUG SMTP: useEhlo true, useAuth false
  DEBUG SMTP: trying to connect to host &quot;plus.smtp.mail.yahoo.com&quot;, port 587, isSSL false
  220 *.smtp.mail.yahoo.com ESMTP ready
  DEBUG SMTP: connected to host &quot;plus.smtp.mail.yahoo.com&quot;, port: 587
  
  EHLO Libsys-PC
  250-*.smtp.mail.yahoo.com
  250-PIPELINING
  250-SIZE 41697280
  250-8 BITMIME
  250 XXXXXXXX
  DEBUG SMTP: Found extension &quot;PIPELINING&quot;, arg &quot;&quot;
  DEBUG SMTP: Found extension &quot;SIZE&quot;, arg &quot;41697280&quot;
  DEBUG SMTP: Found extension &quot;8&quot;, arg &quot;BITMIME&quot;
  DEBUG SMTP: Found extension &quot;XXXXXXXX&quot;, arg &quot;&quot;
  DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
  DEBUG SMTP: useEhlo true, useAuth false
  DEBUG SMTP: trying to connect to host &quot;plus.smtp.mail.yahoo.com&quot;, port 587, isSSL false
  220 *.smtp.mail.yahoo.com ESMTP ready
  DEBUG SMTP: connected to host &quot;plus.smtp.mail.yahoo.com&quot;, port: 587
  
  EHLO Libsys-PC
  250-*.smtp.mail.yahoo.com
  250-PIPELINING
  250-SIZE 41697280
  250-8 BITMIME
  250 XXXXXXXX
  DEBUG SMTP: Found extension &quot;PIPELINING&quot;, arg &quot;&quot;
  DEBUG SMTP: Found extension &quot;SIZE&quot;, arg &quot;41697280&quot;
  DEBUG SMTP: Found extension &quot;8&quot;, arg &quot;BITMIME&quot;
  DEBUG SMTP: Found extension &quot;XXXXXXXX&quot;, arg &quot;&quot;
  DEBUG SMTP: use8bit false
  MAIL FROM:from
  530 5.7.1 Authentication required
  DEBUG SMTP: got response code 530, with response: 530 5.7.1 Authentication required
  
  RSET
  250 2.0.0 OK
  DEBUG SMTP: MessagingException while sending, THROW: 
  com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.1 Authentication required
  
      at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2108)
      at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1609)
      at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1117)
      at javax.mail.Transport.send0(Transport.java:195)
      at javax.mail.Transport.send(Transport.java:124)
      at Mail.main(Mail.java:119)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
  QUIT
  221 2.0.0 Bye
  Exception in thread &quot;main&quot; java.lang.RuntimeException: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.1 Authentication required
  
      at Mail.main(Mail.java:123)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
  Caused by: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.1 Authentication required
  
      at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2108)
      at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1609)
      at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1117)
      at javax.mail.Transport.send0(Transport.java:195)
      at javax.mail.Transport.send(Transport.java:124)
      at Mail.main(Mail.java:119)
      ... 5 more
  
      Process finished with exit code 1
  </code></pre>
  <p>:</p>
  <p><strong>After reflecting my code is :</strong></p>
  <pre><code>     Properties properties = new Properties();
      properties.put(&quot;mail.smtp.host&quot;,&quot;smtp.gmail.com&quot;);
      properties.put(&quot;mail.smtp.port&quot;, 587);
      properties.put(&quot;mail.smtp.auth&quot;,true);
      properties.put(&quot;mail.smtp.starttls.enable&quot;, &quot;true&quot;);
      Session emailSession = Session.getInstance(properties);
      emailSession.setDebug(true);
  
      //create the POP3 store object and connect with the pop server
      try {
  
          MimeMessage message = new MimeMessage(emailSession);
          message.setFrom(new InternetAddress(from));
          message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
          message.setSubject(&quot;Ping&quot;);
          message.setText(&quot;Hello, this is example of sending email  &quot;);
          Transport.send(message,id,password);
  
          System.out.println(&quot;message sent successfully....&quot;);
  
      } catch (MessagingException e) {
          e.printStackTrace();
          throw new RuntimeException(e);
      }
  </code></pre>
  <p>But debug output is same as previous</p>
  <pre><code>    DEBUG: setDebug: JavaMail version 1.5.5
   DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
  DEBUG SMTP: useEhlo true, useAuth true
  DEBUG SMTP: trying to connect to host &quot;smtp.gmail.com&quot;, port 587, isSSL false
  220 smtp.gmail.com ESMTP i62sm9706430pfg.62 - gsmtp
  DEBUG SMTP: connected to host &quot;smtp.gmail.com&quot;, port: 587
  
  EHLO Libsys-PC
  250-smtp.gmail.com at your service, [163.47.140.139]
  250-SIZE 35882577
  250-8BITMIME
  250-ENHANCEDSTATUSCODES
  250-PIPELINING
  250 SMTPUTF8
  DEBUG SMTP: Found extension &quot;SIZE&quot;, arg &quot;35882577&quot;
  DEBUG SMTP: Found extension &quot;8BITMIME&quot;, arg &quot;&quot;
  DEBUG SMTP: Found extension &quot;ENHANCEDSTATUSCODES&quot;, arg &quot;&quot;
  DEBUG SMTP: Found extension &quot;PIPELINING&quot;, arg &quot;&quot;
  DEBUG SMTP: Found extension &quot;SMTPUTF8&quot;, arg &quot;&quot;
  DEBUG SMTP: use8bit false
  MAIL FROM:&lt;rohitsingla6@gmail.com&gt;
  530 5.7.0 Must issue a STARTTLS command first. i62sm9706430pfg.62 - gsmtp
  DEBUG SMTP: got response code 530, with response: 530 5.7.0 Must issue a STARTTLS command first. i62sm9706430pfg.62 - gsmtp
  
  RSET
  250 2.1.5 Flushed i62sm9706430pfg.62 - gsmtp
  DEBUG SMTP: MessagingException while sending, THROW: 
  com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. i62sm9706430pfg.62 - gsmtp
  
      at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2249)
      at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1740)
      at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1239)
      at javax.mail.Transport.send0(Transport.java:255)
      at javax.mail.Transport.send(Transport.java:174)
      at GMail.main(GMail.java:32)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
  QUIT
  221 2.0.0 closing connection i62sm9706430pfg.62 - gsmtp
  com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. i62sm9706430pfg.62 - gsmtp
  
      at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2249)
      at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1740)
      at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1239)
      at javax.mail.Transport.send0(Transport.java:255)
      at javax.mail.Transport.send(Transport.java:174)
      at GMail.main(GMail.java:32)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
  Exception in thread &quot;main&quot; java.lang.RuntimeException: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. i62sm9706430pfg.62 - gsmtp
  
      at GMail.main(GMail.java:38)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
  Caused by: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. i62sm9706430pfg.62 - gsmtp
  
      at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2249)
      at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1740)
      at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1239)
      at javax.mail.Transport.send0(Transport.java:255)
      at javax.mail.Transport.send(Transport.java:174)
      at GMail.main(GMail.java:32)
      ... 5 more
  </code></pre>