javax.mail.AuthenticationFailedException: failed to connect, no password specified?

前端 未结 14 1984
广开言路
广开言路 2020-12-17 10:46

This program attempts to send e-mail but throws a run time exception:

javax.mail.AuthenticationFailedException: failed to connect, no password specified?
         


        
14条回答
  •  再見小時候
    2020-12-17 11:16

    Even when using an Authenticator I had to set mail.smtp.auth property to true. Here is a working example:

    final Properties props = new Properties();
    props.put("mail.smtp.host", config.getSmtpHost());
    props.setProperty("mail.smtp.auth", "true");
    
    Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator()
    {
      protected PasswordAuthentication getPasswordAuthentication()
      {
        return new PasswordAuthentication(config.getSmtpUser(), config.getSmtpPassword());
      }
    });
    

提交回复
热议问题