E-Mail - Verbinden zu web.de

meerie123

Mitglied
Hallo,
der Ausschnitt aus einem größeren Programm soll eine Verbindung mithilfe von JavaMail zu einem web.de-Account erzeugen:
Java:
import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class MailTest {

    // Objekte
    private String protocol,host,user,pw;

    private Properties props;
    private Session session;
    private Store store;


    public MailTest()  {

    protocol = "imap";   
    host     = "smtp.web.de";
    user     = "***";
    pw       = "***";

        try {

            // Ein Properties-Objekt erzeugen
            props = System.getProperties();
       
            // Mail-Host hinzufuegen
            props.put("mail.smtp.host", host);
            props.put("mail.smtp.port", "587");
            props.put("mail.smtp.starttls.enable", "true");
       
           //Authentifikation
            MailAuthenticator auth = new MailAuthenticator(user, pw);
            props.put("mail.smtp.auth", "true");
       
            //ESMTP
            props.put("mail.smtp.allow8bitmime", "true");
       

            // Ein Session-Objekt erzeugen
            session = Session.getDefaultInstance(props, auth);
       
            session.setDebug(true);

            // Ein Store-Objekt erzeugen
            store = session.getStore(protocol);
               
            // Verbindung herstellen
            store.connect(host,587, user, pw);
               
        }    catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }
   
    public static void main(final String[] args) {
        new MailTest();
    }
}

Ausgabe lautet:

Code:
DEBUG: setDebug: JavaMail version 1.5.6
DEBUG: getProvider() returning javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle]
DEBUG IMAP: mail.imap.fetchsize: 16384
DEBUG IMAP: mail.imap.ignorebodystructuresize: false
DEBUG IMAP: mail.imap.statuscachetimeout: 1000
DEBUG IMAP: mail.imap.appendbuffersize: -1
DEBUG IMAP: mail.imap.minidletime: 10
DEBUG IMAP: closeFoldersOnStoreFailure
DEBUG IMAP: trying to connect to host "smtp.web.de", port 587, isSSL false
220 web.de (mrweb002) Nemesis ESMTP Service ready
javax.mail.MessagingException: 220 web.de (mrweb002) Nemesis ESMTP Service ready;
  nested exception is:
        com.sun.mail.iap.ConnectionException: 220 web.de (mrweb002) Nemesis ESMTP Service ready
        at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:731)
        at javax.mail.Service.connect(Service.java:366)
        at MailTest.<init>(mailTest.java:53)
        at MailTest.main(mailTest.java:62)
Caused by: com.sun.mail.iap.ConnectionException: 220 web.de (mrweb002) Nemesis ESMTP Service ready
        at com.sun.mail.imap.protocol.IMAPProtocol.processGreeting(IMAPProtocol.java:321)
        at com.sun.mail.iap.Protocol.<init>(Protocol.java:130)
        at com.sun.mail.imap.protocol.IMAPProtocol.<init>(IMAPProtocol.java:126)
        at com.sun.mail.imap.IMAPStore.newIMAPProtocol(IMAPStore.java:756)
        at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:691)
        ... 3 more

Google spuckt keine brauchbare Lösung aus.

Kann jemand helfen?
 
Was mir auffällt ist, dass du Port 587 verwendest, der für SSL benutzt wird - du hast jedoch SSL nicht aktiviert.
Ergänze für SSL das:
Java:
props.put("mail.smtp.socketFactory.port", "587");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
Aber sonst finde ich die Exception eigenartig, da ich da keine Fehlerursache finden kann.
 
Wie gesagt finde ich es eigenartig, dass du eine Exception bekommst. Selbst die Message enthält keinen Fehlerhinweis sondern 220 web.de - das ist doch nichts schlechtes.
Du solltest statt allen Exceptions nur die Exceptions fangen, die von der Methode geworfen werden können.
 
Zuletzt bearbeitet:
Dann heißt es aber:
Code:
DEBUG: setDebug: JavaMail version 1.5.6
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
javax.mail.NoSuchProviderException: invalid provider
        at javax.mail.Session.getStore(Session.java:592)
        at javax.mail.Session.getStore(Session.java:558)
        at javax.mail.Session.getStore(Session.java:537)
        at MailTest.<init>(MailTest.java:55)
        at MailTest.main(MailTest.java:67)

Provider stimmt aber laut http://www.torsten-horn.de/techdocs/java-smtp.htm#E-Mail-Provider
 

Neue Themen


Zurück
Oben