1

yahoo mailから未読メッセージを読みたいので、次のコードを使用しましたが、エラーが発生します

次のように

javax.mail.MessagingException: Connect failed;
  nested exception is:
    java.io.IOException: Connect failed
    at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:148)
    at javax.mail.Service.connect(Service.java:275)
    at javax.mail.Service.connect(Service.java:156)
    at ReadYahooMail.<init>(ReadYahooMail.java:20)
    at ReadYahooMail.main(ReadYahooMail.java:56)
Caused by: java.io.IOException: Connect failed
    at com.sun.mail.pop3.Protocol.<init>(Protocol.java:104)
    at com.sun.mail.pop3.POP3Store.getPort(POP3Store.java:201)
    at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:144)
    ... 4 more

私は次のコードを使用します

 import java.io.*;
import java.util.*;
import javax.mail.*; 
public class ReadYahooMail {
    public ReadYahooMail(){
        String host = "smtp.mail.yahoo.com";
  String user = "1234";
  String password = "*******"; 
try{
  // Get system properties 
   Properties properties = System.getProperties(); 

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

  // Get a Store object that implements the specified protocol.
  Store store = session.getStore("pop3");

  //Connect to the current host using the specified username and password.
  store.connect(host, user, password);

  //Create a Folder object corresponding to the given name.
  Folder folder = store.getFolder("inbox");

  // Open the Folder.
  folder.open(Folder.READ_ONLY);

  Message[] message = folder.getMessages();

  // Display message.
  for (int i = 0; i < message.length; i++) {

  System.out.println("------------ Message " + (i + 1) + " ------------");

  System.out.println("SentDate : " + message[i].getSentDate());
  System.out.println("From : " + message[i].getFrom()[0]);
  System.out.println("Subject : " + message[i].getSubject());
  System.out.print("Message : ");

  InputStream stream = message[i].getInputStream();
  while (stream.available() != 0) {
  System.out.print((char) stream.read());
  }
  System.out.println();
  }

  folder.close(true);
  store.close();
}
catch(Exception e){
    e.printStackTrace();
}

    }
    public static void main(String args[]){
        ReadYahooMail r=new ReadYahooMail();
    }

}
4

2 に答える 2

1

うーん、この一例のようにIMAPプロトコルを使用するかもしれません:

JavaでIMAPを使用してYahooからメールを取得する

于 2012-09-03T07:08:42.480 に答える
0

他の電子メールプロバイダーとは異なり、Yahooは無料のPOPまたはIMAPサービスを提供していません。したがって、これがIOExceptionの原因である可能性があります。

于 2012-09-03T07:14:36.153 に答える