Created
December 7, 2023 10:56
Extract Emails via 5 Most Popular Methods in Java
This file contains 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
PersonalStorage pst = PersonalStorage.fromFile("storage.pst"); | |
FolderInfo folder = pst.getRootFolder().getSubFolder("Inbox"); | |
for (MessageInfo messageInfo : folder.enumerateMessages()) { | |
MapiMessage msg = pst.extractMessage(messageInfo); | |
} |
This file contains 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
IGraphClient client = GraphClient.getClient(tokenProvider); | |
GraphMessageInfoCollection messageInfoColl = client.listMessages(GraphKnownFolders.Inbox); | |
for (GraphMessageInfo messageInfo : messageInfoColl) { | |
MapiMessage message = client.fetchMessage(messageInfo.getItemId()); | |
} |
This file contains 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
ImapClient client = new ImapClient("localhost", "user", "password"); | |
client.setSecurityOptions(SecurityOptions.Auto); | |
try { | |
ImapMessageInfoCollection messageInfoCol = client.listMessages(); | |
for (ImapMessageInfo messageInfo : messageInfoCol) { | |
MailMessage eml = client.fetchMessage(messageInfo.getUniqueId()); | |
} | |
} catch (Exception ex) { | |
System.out.println(ex.getMessage()); | |
} finally { | |
client.dispose(); | |
} |
This file contains 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
Pop3Client client = new Pop3Client("pop3.server.com", "username", "password"); | |
client.setSecurityOptions(SecurityOptions.Auto); | |
try { | |
Pop3MessageInfoCollection messageInfoCol = pop3Client.listMessages(); | |
for (Pop3MessageInfo messageInfo : messageInfoCol) { | |
MailMessage eml = client.fetchMessage(messageInfo.getSequenceNumber()); | |
} | |
} catch (Exception ex) { | |
System.out.println(ex.getMessage()); | |
} finally { | |
client.dispose(); | |
} |
This file contains 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
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "UserName", "Password"); | |
ExchangeMessageInfoCollection messageInfoCol = client.listMessages(client.getMailboxInfo().getInboxUri()); | |
for (ExchangeMessageInfo msgInfo : (Iterable<ExchangeMessageInfo>) messageInfoCol) { | |
String strMessageURI = msgInfo.getUniqueUri(); | |
MailMessage eml = client.fetchMessage(strMessageURI); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment