[英]JavaMail API - error getting messages
I am working through oracle's tutorial on using the javamail api to access my email. 我正在阅读有关使用javamail api访问我的电子邮件的oracle教程。 Here is my code:
这是我的代码:
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();
}
}
And here is the error I am receiving: 这是我收到的错误:
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
Any ideas what am I doing wrong? 有什么想法我做错了吗?
Also, on Google's page, they stated that users would need to use SSL to connect via POP3. 此外,他们在Google的页面上指出,用户需要使用SSL才能通过POP3连接。 How will I implement that in the JavaMail API?
我将如何在JavaMail API中实现它? Thanks!
谢谢!
As indicated, your error is in 如所示,您的错误在
System.out.println(message[i].writeTo());
There are two problems: 有两个问题:
Message.writeTo() takes an OutputStream as an argument, and you havent supplied one. Message.writeTo()将OutputStream作为参数,而您尚未提供它。
writeTo() returns void, so is not a valid argument to println() writeTo()返回void,因此不是println()的有效参数
Here is some sample code that connects to GMail via the java mail api, using POP3 and SSL 这是一些示例代码,它们使用POP3和SSL通过java邮件api连接到GMail
消息[I] .writeTo(System.out的);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.