Dart
Dart
Connecting to GMAIL using IMAP
Demonstrates how to connect to GMAIL using IMAP.Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
final imap = CkImap();
// Turn on session logging:
imap.keepSessionLog = true;
// Connect to GMail
// Use TLS
imap.ssl = true;
imap.port = 993;
try {
imap.connect('imap.gmail.com');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Login
// Your login is typically your GMail email address.
try {
imap.login('username@gmail.com', 'myPassword');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Select an IMAP mailbox
try {
imap.selectMailbox('Inbox');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Show the session log.
print(imap.sessionLog);
// Disconnect from the IMAP server.
imap.disconnect();
}