Hallo,
ich versuche gerade mich mit Google zu verbinden um Emails via Java Mail abzurufen.
Das Senden klappt super, aber beim Empfangen habe ich Probleme:
- In Google Mail selbst habe ich IMAP aktiviert.
Hier meine Methode, was passt bei den Einstellungen nicht?
Prinzipiell soll die Methode so ausgelegt sein, dass es für jegliche IMAP Inbox passt, nicht nur für Google Mail
ich versuche gerade mich mit Google zu verbinden um Emails via Java Mail abzurufen.
Das Senden klappt super, aber beim Empfangen habe ich Probleme:
- In Google Mail selbst habe ich IMAP aktiviert.
Hier meine Methode, was passt bei den Einstellungen nicht?
Prinzipiell soll die Methode so ausgelegt sein, dass es für jegliche IMAP Inbox passt, nicht nur für Google Mail
Java:
public boolean checkIMAP(String host, int port, final String username, final String password, boolean auth,
String enctype) throws Exception {
boolean result = false;
try {
Properties props = new Properties();
props.put("mail.imap.host", host);
props.put("mail.imap.user", username);
props.put("mail.imap.password", password);
props.put("mail.imap.port", port);
if (enctype.contains("TLS")) {
props.put("mail.imap.starttls.enable", "true");
}
else if (enctype.contains("SSL")) {
props.setProperty("mail.imap.ssl.enable", "true");
}
Session session = Session.getInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
Store store = session.getStore("imaps");
store.connect(host, username, password);
result = true;
} catch (AuthenticationFailedException e) {
throw new AuthenticationFailedException("Authentication Failed");
} catch (MessagingException e) {
throw new Exception("Messaging Exception Occurred");
} catch (Exception e) {
throw new Exception("Unknown Exception");
}
return result;
}