Dart
Dart
Select an IMAP Mailbox
See more IMAP Examples
Demonstrates the Chilkat Imap.SelectMailbox method, which opens a mailbox for read-write access. A mailbox must be selected before message fetch, search, flag, copy, move, or expunge operations that act on messages. This example selects the Inbox.
Background: In IMAP, mail is organized into mailboxes (folders), and most message operations act on the currently selected one — so selecting a mailbox is the required step between logging in and working with messages.
SelectMailbox opens it read-write, allowing changes such as setting flags or deleting. When you only need to read and must not alter anything (including the \Seen flag), use ExamineMailbox instead.Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// Demonstrates the Imap.SelectMailbox method, which opens a mailbox for read-write access.
// A mailbox must be selected before message fetch, search, flag, copy, move, or expunge
// operations that act on messages.
final imap = CkImap();
imap.ssl = true;
imap.port = 993;
try {
imap.connect('imap.example.com');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
try {
imap.login('user@example.com', 'myPassword');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Open the Inbox for read-write access.
try {
imap.selectMailbox('Inbox');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
print('Inbox selected for read-write access.');
try {
imap.disconnect();
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
}