Read the complete article on how to create and delete folders on MS Exchange Server with EWS in Java: https://blog.aspose.com/2022/03/01/manage-folders-on-ms-exchange-server-in-java/
Last active
April 5, 2022 04:09
-
-
Save aspose-com-gists/21cb4c6bb9e8748dcd7e5a15cd1c9e4c to your computer and use it in GitHub Desktop.
Create and Delete Folders on MS Exchange Server 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
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", | |
"domain"); | |
// Get inbox URI (to create folder in inbox) | |
String inbox = client.getMailboxInfo().getInboxUri(); | |
// Specify folder name | |
String folderName1 = "EMAILNET-35054"; | |
try { | |
// Create folder | |
client.setUseSlashAsFolderSeparator(true); | |
client.createFolder(inbox, folderName1); | |
} catch (Exception e) { | |
// Do something | |
} |
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
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Get inbox URI (to create folder in inbox) | |
String inbox = client.getMailboxInfo().getInboxUri(); | |
// Specify folder name | |
String folderName1 = "EMAILNET-35054"; | |
// Specify subfolder name | |
String subFolderName = "2015"; | |
String folderName2 = folderName1 + "/" + subFolderName; | |
try | |
{ | |
// Create folder | |
client.setUseSlashAsFolderSeparator(true); | |
if (!client.folderExists(inbox, folderName1)) | |
{ | |
// Create folder | |
client.createFolder(inbox, folderName1); | |
} | |
// Create subfolder | |
client.createFolder(inbox, folderName2); | |
} | |
catch(Exception e) | |
{ | |
// Do something | |
} |
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
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Get inbox URI (to create folder in inbox) | |
String inbox = client.getMailboxInfo().getInboxUri(); | |
// Specify folder name | |
String folderName1 = "EMAILNET-35054"; | |
ExchangeFolderInfo rootFolderInfo = null; | |
try | |
{ | |
ExchangeFolderInfo[] referenceToRootFolderInfo = { rootFolderInfo }; | |
// Check if folder exists | |
boolean outRefCondition0 = client.folderExists(inbox, folderName1, /* out */ referenceToRootFolderInfo); | |
rootFolderInfo = referenceToRootFolderInfo[0]; | |
if (outRefCondition0) { | |
// Delete folder | |
client.deleteFolder(rootFolderInfo.getUri(), true); | |
} | |
} | |
catch(Exception e) | |
{ | |
// Do something | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment