Dart
Dart
Append MIME from a StringBuilder with Flags
See more IMAP Examples
Demonstrates the Chilkat Imap.AppendMimeWithFlagsSb method, which uploads MIME contained in a StringBuilder and sets its initial system flags. The first argument is the mailbox, the second is the StringBuilder, and the third through sixth set \Seen, \Flagged, \Answered, and \Draft. This example uploads to Drafts with the draft flag set.
Background: This is the
StringBuilder form of AppendMimeWithFlags. Passing the MIME as a StringBuilder avoids copying a large message into an intermediate string and is convenient when you already built or loaded the message into a StringBuilder (for example with LoadFile).Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// Demonstrates the Imap.AppendMimeWithFlagsSb method, which uploads MIME contained in a
// StringBuilder and sets its initial system flags. The 1st argument is the mailbox, the 2nd
// is the StringBuilder, and the 3rd through 6th set \Seen, \Flagged, \Answered, and \Draft.
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;
}
// Build the email to be uploaded.
final email = CkEmail();
email.subject = 'Meeting agenda';
email.from = 'Alice <alice@example.com>';
email.addTo('Bob', 'bob@example.com');
email.body = 'Let\'s meet at 10am to review the agenda.';
final String mimeText;
try {
mimeText = email.getMime();
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Load the MIME into a StringBuilder. (A StringBuilder can also be filled via LoadFile.)
final sbMime = CkStringBuilder();
sbMime.append(mimeText);
// Choose the initial flags. Named variables make each argument's meaning clear at the call.
final seen = false;
final flagged = false;
final answered = false;
final draft = true;
// Upload to "Drafts" with the \Draft flag set.
try {
imap.appendMimeWithFlagsSb('Drafts', sbMime, seen, flagged, answered, draft);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
print('Appended UID: ${imap.appendUid}');
try {
imap.disconnect();
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
}