-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimplePOP3.java
More file actions
30 lines (24 loc) · 1.01 KB
/
SimplePOP3.java
File metadata and controls
30 lines (24 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.util.Properties;
import javax.mail.*;
public class SimplePOP3 {
public static void main(String[] args) throws Exception {
Properties p = new Properties();
p.put("mail.store.protocol", "pop3");
p.put("mail.pop3.host", "pop.gmail.com");
p.put("mail.pop3.port", "995");
p.put("mail.pop3.ssl.enable", "true");
Session s = Session.getInstance(p);
Store store = s.getStore("pop3");
store.connect("pop.gmail.com", "your@gmail.com", "your-password");
Folder inbox = store.getFolder("INBOX");
inbox.open(Folder.READ_ONLY);
Message[] msgs = inbox.getMessages();
System.out.println("📬 Emails: " + msgs.length);
for (int i = 0; i < Math.min(3, msgs.length); i++) {
System.out.println("\n" + (i+1) + ". " + msgs[i].getSubject());
System.out.println(" From: " + msgs[i].getFrom()[0]);
}
inbox.close(false);
store.close();
}
}