Created
July 3, 2016 15:40
-
-
Save peanutpi/b6bcc090d58a445de4e357deccdb40b9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Properties; | |
import javax.mail.Folder; | |
import javax.mail.Message; | |
import javax.mail.Session; | |
import javax.mail.Store; | |
public class MailReader { | |
private static final String FOLDER = "Inbox"; | |
private static final String PASSWORD = "secretPassword"; | |
private static final String EMAIL_ID = "[email protected]"; | |
private static final String IMAP_SERVER = "imap.mail.domain.com"; | |
public static void main(String[] args) throws Exception { | |
Properties props = new Properties(); | |
props.setProperty("mail.store.protocol", "imaps"); | |
try { | |
Session session = Session.getInstance(props, null); | |
Store store = session.getStore(); | |
store.connect(IMAP_SERVER, EMAIL_ID, PASSWORD); | |
Folder inbox = store.getFolder(FOLDER); | |
inbox.open(Folder.READ_ONLY); | |
Message[] msgs = inbox.getMessages(); | |
int count = 0; | |
for (Message msg : msgs) { | |
System.out.println("MESSAGE FROM :: "+msg.getFrom()); | |
System.out.println("MESSAGE SUBJECT :: "+msg.getSubject()); | |
System.out.println("MESSAGE CONTECT :: \n "+msg.getContent()); | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment