Article Image
read

Background


For some ongoing development projects I needed a reliable email server and decided to go for the T-Online mail infrastructure.

Sending emails via java seemed to easy using the great JAVAMAIL implementation, however the STARTTLS feature resulted in some messy testing times.

Going for the real solution code...


Properties props = new Properties();
props.put("mail.imap.host" , "secureimap.t-online.de");
props.put("mail.imap.user" , USERNAME);
props.put("mail.imap.ssl.enable", "true");

// Start SSL connection

props.put("mail.imap.socketFactory" , "993" );
props.put("mail.imap.socketFactory.class" , "javax.net.ssl.SSLSocketFactory" );
props.put("mail.imap.port" , "993");

Session session = Session.getDefaultInstance(props , new Authenticator() {
    @Override
    protected PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication( USERNAE , PASSWORD);
    }
});

Store store  = session.getStore("imap");
store.connect("secureimap.t-online.de" , USERNAME , PASSWORD);
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
int count = folder.getMessageCount();
System.out.println(count);


Blog Logo

Markus Schmall


Published

Image

Homepage of Markus 'Flake' Schmall

A Jekyll theme - Medium inspired

Back to Overview