Reputation: 13672
I am working through oracle's tutorial on using the javamail api to access my email. 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 protected]","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. How will I implement that in the JavaMail API? Thanks!
Upvotes: 0
Views: 445
Reputation: 30088
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.
writeTo() returns void, so is not a valid argument to println()
Here is some sample code that connects to GMail via the java mail api, using POP3 and SSL
Upvotes: 3