Javaを使用してメールを接続しようとしています
スレッド「メイン」での例外 javax.mail.AuthenticationFailedException: POP サーバーが定義されていません。アカウントで 127.0.0.1 の代わりに実際のサーバー アドレスを使用します。com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:208) で javax.mail.Service.connect(Service.java:295) で javax.mail.Service.connect(Service.java:176) でPOP3Clint.main(POP3Clint.java:28) Java 結果: 1
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
public class POP3Clint {
public static void main(String[] args) throws Exception {
String host = "192.168.10.205";
String user = "test";
String password = "test";
// 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);
// Get the messages from the server
Message[] messages = folder.getMessages();
// Display message.
for (int i = 0; i < messages.length; i++) {
System.out.println("------------ Message " + (i + 1) + " ------------");
// Here's the big change...
String from = InternetAddress.toString(messages[i].getFrom());
if (from != null) {
System.out.println("From: " + from);
}
String replyTo = InternetAddress.toString(
messages[i].getReplyTo());
if (replyTo != null) {
System.out.println("Reply-to: " + replyTo);
}
String to = InternetAddress.toString(
messages[i].getRecipients(Message.RecipientType.TO));
if (to != null) {
System.out.println("To: " + to);
}
String cc = InternetAddress.toString(
messages[i].getRecipients(Message.RecipientType.CC));
if (cc != null) {
System.out.println("Cc: " + cc);
}
String bcc = InternetAddress.toString(
messages[i].getRecipients(Message.RecipientType.BCC));
if (bcc != null) {
System.out.println("Bcc: " + to);
}
String subject = messages[i].getSubject();
if (subject != null) {
System.out.println("Subject: " + subject);
}
Date sent = messages[i].getSentDate();
if (sent != null) {
System.out.println("Sent: " + sent);
}
Date received = messages[i].getReceivedDate();
if (received != null) {
System.out.println("Received: " + received);
}
System.out.println();
}
folder.close(true);
store.close();
}
}
---編集済み__
Exception in thread "main" javax.mail.AuthenticationFailedException: EOF on socket
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:208)
at javax.mail.Service.connect(Service.java:295)
at javax.mail.Service.connect(Service.java:176)
at POP3Clint.main(POP3Clint.java:35)
Java Result: 1
この例外は、ウイルス対策を無効にした場合に発生します