Java E-Mail Versand via Yahoo.De

StillerRegen

Mitglied
Halli Hallo an Alle fleißen Leser :)

wie ihr im Titel schon entnehmen könnt, möchte ich Per Java einen E-Mail Versand mit Yahoo machen, jedoch werden mir ein Paar Fehler ausgegeben.

CODE:

Java:
 String from = "Abc@yahoo.de";
                         String pass ="Passwort";
               
                       String to = "Abc@outlook.de";
                       String host = "smtp.mail.yahoo.de";

                       // Get system properties
                       Properties properties = System.getProperties();
                       // Setup mail server
                       properties.put("mail.smtp.starttls.enable", "true");
                       properties.put("mail.smtp.host", host);
                       properties.put("mail.smtp.user", from);
                       properties.put("mail.smtp.password", pass);
                       properties.put("mail.smtp.port", "587");
                       properties.put("mail.smtp.auth", "true");

                       // Get the default Session object.
                       Session session = Session.getDefaultInstance(properties);

                       try{
                          // Create a default MimeMessage object.
                          MimeMessage message = new MimeMessage(session);

                          // Set From: header field of the header.
                          message.setFrom(new InternetAddress(from));

                          // Set To: header field of the header.
                          message.addRecipient(Message.RecipientType.TO,
                                                   new InternetAddress(to));

                          // Set Subject: header field
                          message.setSubject("This is the Subject Line!");

                          // Now set the actual message
                          message.setText("Der Test ist geglückt!");

                          // Send message
                          Transport transport = session.getTransport("smtp");
                          transport.connect(host, from, pass);
                          transport.sendMessage(message, message.getAllRecipients());
                          transport.close();
                          System.out.println("Sent message successfully....");
                       }catch (MessagingException mex) {
                          mex.printStackTrace();
                       }
                    }

Fehler:


Java:
at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:965)
    at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:876)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:780)
    at javax.mail.Service.connect(Service.java:366)
    at javax.mail.Service.connect(Service.java:246)
    at Funktion.Geburtstag.main(Geburtstag.java:144)
javax.mail.AuthenticationFailedException: 535 5.7.1 Authentication failed

Sieht jemand wo der Fehler ist?
 
Hi,

Der Mailserver lehnt die Anmeldung ab, entweder Benutzername oder Passwort sind falsch. Ich vermute, dass du als Benutzername nur den Namen (ohne dem @yahoo) angeben musst.

Grüsse,
BK
 
Hey Bratkartoffel,

habe das @yahoo.de jetzt rausgenommen, immernoch der selbe fehler,
habe sogar bei Email adresse und Passwort Copy Paste gemacht und konnte mich in yahoo anmelden.

Vlt. muss das Passwort ja anders übergeben werden vlt. nicht als String sondern als Char?
 
Hey,

habe ich auch schon Probiert, immer noch dasselbe.

Habe mal einen anderen Code Probiert:

Java:
    final String fromEmail = "myemailid@gmail.com"; 
    final String password = "mypassword"; 
    final String toEmail = "myemail@yahoo.com"; 
              Properties props = new Properties();       
  props.put("mail.smtp.host", "smtp.gmail.com"); 
  props.put("mail.smtp.port", "587"); 
       props.put("mail.smtp.auth", "true"); 
        props.put("mail.smtp.starttls.enable", "true");                
       Authenticator auth = new Authenticator() { 
protected PasswordAuthentication getPasswordAuthentication() {                 
return new PasswordAuthentication(fromEmail, password);         
    }     
    };      
   Session session = Session.getInstance(props, auth);                 
 EmailUtil.sendEmail(session, toEmail,"TLSEmail Testing Subject", "TLSEmail Testing Body");        
      }     
}

Alles soweit in Ordnung außer die letzte Zeile, dort sagt er mir :

EMailUtil Cannot Be resolved
 
Hi,

EmailUtil ist eine Komponente einer unbekannten Bibliothek, keine Ahnung was mit der gemeint ist.
Was hat denn das Debugging gebracht? Was wurde geschrieben?

Grüsse,
BK
 
Hi,

ich würde hier nicht gleich auf telnet zurückgreifen und zuerst mal per Java-Bordmittel debuggen:
A: Turn on session debugging by invoking the method setDebug(true) on the Session object in your code. That will cause debug information to be printed to the console, including a protocol trace. If you passed the System properties to the Session when you created it, you can simply run your program with java -Dmail.debug=true ...

Grüsse,
BK
 
Hey

Vielen Dank.

Ganz Ganz große Log File :

Java:
DEBUG: setDebug: JavaMail version 1.6.2
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.mail.yahoo.com", port 587, isSSL false
220 smtp.mail.yahoo.com ESMTP ready
DEBUG SMTP: connected to host "smtp.mail.yahoo.com", port: 587
EHLO WIN-VA2E0PGQ7BE
250-smtp423.mail.ir2.yahoo.com Hello WIN-VA2E0PGQ7BE [80.187.96.65])
250-PIPELINING
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-SIZE 41697280
250 STARTTLS
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "SIZE", arg "41697280"
DEBUG SMTP: Found extension "STARTTLS", arg ""
STARTTLS
220 2.0.0 Ready to start TLS
EHLO WIN-VA2E0PGQ7BE
250-smtp423.mail.ir2.yahoo.com Hello WIN-VA2E0PGQ7BE [80.187.96.65])
250-PIPELINING
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-SIZE 41697280
250 AUTH PLAIN LOGIN XOAUTH2 OAUTHBEARER
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "SIZE", arg "41697280"
DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN XOAUTH2 OAUTHBEARER"
DEBUG SMTP: protocolConnect login, host=smtp.mail.yahoo.com, user=abc@yahoo.de, password=<non-null>
DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM XOAUTH2
DEBUG SMTP: Using mechanism LOGIN
DEBUG SMTP: AUTH LOGIN command trace suppressed
DEBUG SMTP: AUTH LOGIN failed
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.mail.yahoo.de", port 587, isSSL false
220 smtp.mail.yahoo.com ESMTP ready
DEBUG SMTP: connected to host "smtp.mail.yahoo.de", port: 587
EHLO WIN-VA2E0PGQ7BE
250-smtp420.mail.ir2.yahoo.com Hello WIN-VA2E0PGQ7BE [80.187.96.65])
250-PIPELINING
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-SIZE 41697280
250 STARTTLS
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "SIZE", arg "41697280"
DEBUG SMTP: Found extension "STARTTLS", arg ""
STARTTLS
220 2.0.0 Ready to start TLS
EHLO WIN-VA2E0PGQ7BE
250-smtp420.mail.ir2.yahoo.com Hello WIN-VA2E0PGQ7BE [80.187.96.65])
250-PIPELINING
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-SIZE 41697280
250 AUTH PLAIN LOGIN XOAUTH2 OAUTHBEARER
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "SIZE", arg "41697280"
DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN XOAUTH2 OAUTHBEARER"
DEBUG SMTP: protocolConnect login, host=smtp.mail.yahoo.de, user=abc@yahoo.de, password=<non-null>
DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM XOAUTH2
DEBUG SMTP: Using mechanism LOGIN
DEBUG SMTP: AUTH LOGIN command trace suppressed
DEBUG SMTP: AUTH LOGIN failed
 
Hi,

sorry dass ich erst jetzt antworte, habe den Thread aus den Augen verloren.
Das Log sagt eigentlich genau das, was ich schon vermutet habe:
Code:
AUTH LOGIN failed

Benutzername / Passwort sind falsch. Ausserdem scheint der Hostname nicht zu stimmen. ".yahoo.de" ist falsch, mMn müsste es ".yahoo.com" sein.

Grüsse,
BK
 
Zurück