我正在阅读 oracle 关于使用 javamail api 访问我的电子邮件的教程。这是我的代码:
import javax.mail.*;
import javax.mail.internet.*;
import java.util.Scanner;
import java.util.Properties;
public class MailClient {
public static void main(String[] args) {
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
Store store = session.getStore("pop3");
store.connect("pop.gmail.com","email@gmail.com","password");
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
Message message[] = folder.getMessages();
int i = message.length;
for (int a=0;a<i;a++) {
System.out.println(message[i].writeTo());
}
Scanner pause = new Scanner(System.in);
folder.close(false);
store.close();
}
}
这是我收到的错误:
MailClient.java:20 error: method writeTo in interface Part cannot be applied to given types;
System.out.println(message[i].writeTo());
required: OutputStream
found: no arguments
reason: actual and formal argument lists differ in length
1 error
任何想法我做错了什么?
此外,在 Google 的页面上,他们表示用户需要使用 SSL 才能通过 POP3 进行连接。我将如何在 JavaMail API 中实现它?谢谢!