0

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!

2 Answers 2

3

As indicated, your error is in

System.out.println(message[i].writeTo());

There are two problems:

  1. Message.writeTo() takes an OutputStream as an argument, and you havent supplied one.

  2. 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

Sign up to request clarification or add additional context in comments.

Comments

1

message[i].writeTo(System.out);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.