Ondersteuning voor IMAP IDLE‑opdracht en extensies
Contents
[
Hide
]
Ondersteuning voor IMAP Idle‑opdracht
Aspose.Email API ImapClient biedt de mogelijkheid om een verbinding met de server te openen en te wachten op de aankomst van een e‑mailbericht. Dit voorkomt dat de server continu gepollt moet worden voor inkomende e‑mail. De onderstaande codefragment toont hoe u ondersteuning voor IMAP Idle‑commando kunt gebruiken.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
// Connect and log in to IMAP
ImapClient client = new ImapClient("imap.domain.com", "username", "password");
client.startMonitoring(new ImapMonitoringEventHandler() {
public void invoke(Object sender, ImapMonitoringEventArgs e) {
System.out.println(e.getNewMessages().length);
System.out.println(e.getDeletedMessages().length);
}
});
client.stopMonitoring("Inbox");
Ondersteuning voor IMAP‑extensies
Aspose.Email API biedt ondersteuning voor IMAP‑extensies. De volgende IMAP‑extensies worden momenteel door de API ondersteund. Deze IMAP‑extensies worden niet door alle servers ondersteund.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
final ImapClient client = new ImapClient("imap.gmail.com", 993, "username", "password");
try {
// Set SecurityOptions
client.setSecurityOptions(SecurityOptions.Auto);
System.out.println(client.getIdSupported());
ImapIdentificationInfo serverIdentificationInfo1 = client.introduceClient();
ImapIdentificationInfo serverIdentificationInfo2 = client.introduceClient(ImapIdentificationInfo.getDefaultValue());
// Display ImapIdentificationInfo properties
System.out.println(serverIdentificationInfo1.toString() + serverIdentificationInfo2.toString());
System.out.println(serverIdentificationInfo1.getName());
System.out.println(serverIdentificationInfo1.getVendor());
System.out.println(serverIdentificationInfo1.getSupportUrl());
System.out.println(serverIdentificationInfo1.getVersion());
} finally {
if (client != null)
client.dispose();
}
IMAP4 Uitgebreid Lijst‑commando
De volgende code‑snippet toont hoe je het uitgebreide lijst‑commando van IMAP4 gebruikt.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
final ImapClient client = new ImapClient("imap.gmail.com", 993, "username", "password");
try {
ImapFolderInfoCollection folderInfoCol = client.listFolders("*");
System.out.println("Extended List Supported: " + client.getExtendedListSupported());
for (ImapFolderInfo folderInfo : (Iterable<ImapFolderInfo>) folderInfoCol) {
if (folderInfo.getName().equals("[Gmail]/All Mail"))
System.out.println("Has Children: " + folderInfo.hasChildren());
if (folderInfo.getName().equals("[Gmail]/Bin"))
System.out.println("Bin has children? " + folderInfo.hasChildren());
if (folderInfo.getName().equals("[Gmail]/Drafts"))
System.out.println("Drafts has children? " + folderInfo.hasChildren());
if (folderInfo.getName().equals("[Gmail]/Important"))
System.out.println("Important has Children? " + folderInfo.hasChildren());
if (folderInfo.getName().equals("[Gmail]/Sent Mail"))
System.out.println("Sent Mail has Children? " + folderInfo.hasChildren());
if (folderInfo.getName().equals("[Gmail]/Spam"))
System.out.println("Spam has Children? " + folderInfo.hasChildren());
if (folderInfo.getName().equals("[Gmail]/Starred"))
System.out.println("Starred has Children? " + folderInfo.hasChildren());
}
} finally {
if (client != null)
client.dispose();
}