title: "530 Authentication required" SMTP and I don't know why
body: <p>I wrote an emailSender with the javax.mail library. I don't know where my mistake is, because in the video from where the code is it worked.</p>
  <p>The Video: <a href="https://www.youtube.com/watch?v=bkpHQD9e5hc&amp;t=1630s" rel="nofollow noreferrer">https://www.youtube.com/watch?v=bkpHQD9e5hc&amp;t=1630s</a></p>
  <p>I also saw the other question on this website to this topic but no solution of these worked for my problem</p>
  <p>Code:</p>
  <pre><code>public class MailSender {
  
      protected Session mailSession;
  
      public void login(String smtpHost, String smtpPort, String username, String password) {
          Properties props = new Properties();
          props.put(&quot;mail.smtp.host&quot;, smtpHost);
          props.put(&quot;mail.smtp.socketFactory.port&quot;, smtpPort);
          props.put(&quot;mail.smtp.socketFactory.class&quot;, &quot;javax.net.ssl.SSLSocketFactory&quot;);
          props.put(&quot;mail.smtp.auth&quot;, &quot;true&quot;);
          props.put(&quot;mail.smtp.port&quot;, smtpPort);
  
          Authenticator auth = new Authenticator() {
              @Override
              protected PasswordAuthentication getPasswordAuthentication() {
                  return new PasswordAuthentication(username, password);
              }
          };
  
          this.mailSession = Session.getDefaultInstance(props, auth);
          System.out.println(&quot;Eingeloggt.&quot;);
      }
  
      public void send(String senderMail, String senderName, String receiverAddresses, String subject, String message, String username, String password)
              throws MessagingException, IllegalStateException, UnsupportedEncodingException {
          if (mailSession == null) {
              throw new IllegalStateException(&quot;Du musst dich zuerst einloggen (login()-Methode)&quot;);
          }
  
          MimeMessage msg = new MimeMessage(mailSession);
          msg.addHeader(&quot;Content-type&quot;, &quot;text/HTML; charset=UTF-8&quot;);
          msg.addHeader(&quot;format&quot;, &quot;flowed&quot;);
          msg.addHeader(&quot;Content-Transfer-Encoding&quot;, &quot;8bit&quot;);
  
          msg.setFrom(new InternetAddress(senderMail, senderName));
          msg.setReplyTo(InternetAddress.parse(senderMail, false));
          msg.setSubject(subject, &quot;UTF-8&quot;);
          msg.setText(message, &quot;UTF-8&quot;);
          msg.setSentDate(new Date());
  
          msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(receiverAddresses, false));
  
          System.out.println(&quot;Versende E-Mail...&quot;);
          Transport.send(msg, username, password);
          System.out.println(&quot;E-Mail versendet.&quot;);
      }
  }
  </code></pre>