0

here is my configuration to send a mail to my smtp server but it's not use session authenticator and force me to enter credential from console and when I enter them from console it successfully send mail, which part of my configuration is wrong.

        Properties properties = new Properties();
    //clear it later 

    properties.setProperty("mail.debug", "true");
    properties.put("mail.smtp.socketFactory.port", "587");
    properties.put("mail.smtp.auth", true);
    properties.put("mail.smtp.starttls.enable", "true");
    properties.put("mail.smtp.host", "mail.example.com");
    properties.put("mail.smtp.port", "587");

    properties.put("mail.smtp.host", "mail.example.com");
    properties.put("mail.smtp.sasl.enable","true");   
    properties.put("mail.smtp.sasl.mechanisms","GSSAPI");
    properties.put("mail.smtp.sasl.authorizationid","admin");
    properties.put("mail.smtp.sasl.realm","EXAMPLE.COM");

    System.setProperty( "sun.security.krb5.debug", "true");
    System.setProperty( "java.security.krb5.realm", "EXAMPLE.COM");
    System.setProperty( "java.security.krb5.kdc", "ipa.example.com"); 


    URL jaasConfigURL = this.getClass().getResource("jaas.conf");
    jaasConfigURL.getFile();
    String jaasConfigFile = jaasConfigURL.getFile();
    System.out.println(jaasConfigFile);
    System.setProperty( "java.security.auth.login.config", jaasConfigFile);
    System.setProperty( "javax.security.auth.useSubjectCredsOnly", "false");

    session = Session.getInstance(properties, new Authenticator() {
        @Override
        protected PasswordAuthentication getPasswordAuthentication(){
            return new PasswordAuthentication("admin", "password");
        }
     });
        session.setDebug(true);
    MimeMessage mime = new SMTPMessage(session);
    mime.setFrom(new InternetAddress(from));
    mime.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
    mime.setSubject("test");
    mime.setText("hello world!");
    Transport.send(mime);

and my jaas.conf file

krb5_initiate{
com.sun.security.auth.module.krb5LoginModule required
useTicketCache="true"
doNotPrompt="true"
debug="true";
};
badger
  • 2,908
  • 1
  • 13
  • 32
  • 1
    As described in the [SASL documentation](http://docs.oracle.com/javase/8/docs/technotes/guides/security/sasl/sasl-refguide.html), the GSSAPI SASL implementation doesn't use any SASL callbacks, which is why the JavaMail Authenticator is never used. The SASL documentation also describes how to use JAAS to login to Kerberos. I have no experience with that myself. If that's not working, you might find more help in the [OpenJDK security group](http://openjdk.java.net/groups/security/). – Bill Shannon Apr 25 '17 at 19:42
  • @BillShannon thank you so much bill – badger Apr 26 '17 at 16:20

0 Answers0