Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to set Email Client in Java?
    text
    copied!<p>i'm trying the very simple Email Client in java. When i launch the programe i have an error message:</p> <pre><code>Exception in thread "main" javax.mail.AuthenticationFailedException: EOF on socket at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:146) at javax.mail.Service.connect(Service.java:297) at javax.mail.Service.connect(Service.java:156) at SimpleEmailClient2.main(SimpleEmailClient2.java:21) Java Result: 1 </code></pre> <p>Why? i use Gmail account and i set the POP and IMAP enabled What could be the possible error in my code? Thank you</p> <p>here is the code:</p> <pre><code>import java.util.Properties; import javax.mail.Authenticator; import javax.mail.Folder; import javax.mail.Message; import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.mail.Store; public class SimpleEmailClient2 { public static void main(String[] args) throws Exception { Properties props = new Properties(); String host = "pop.gmail.com"; String provider = "pop3"; Session session = Session.getDefaultInstance(props, new MailAuthenticator()); Store store = session.getStore(provider); store.connect(host, null, null); Folder inbox = store.getFolder("INBOX"); if (inbox == null) { System.out.println("No INBOX"); System.exit(1); } inbox.open(Folder.READ_ONLY); Message[] messages = inbox.getMessages(); for (int i = 0; i &lt; messages.length; i++) { System.out.println("Message " + (i + 1)); messages[i].writeTo(System.out); } inbox.close(false); store.close(); } } class MailAuthenticator extends Authenticator { public MailAuthenticator() { } public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("email@gmail.com", "password"); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload