Dart
Dart
Remove a Single Attached Message from an Email
See more Email Object Examples
Demonstrates the Chilkat Email.RemoveAttachedMessage method, which removes the Nth message/rfc822 sub-part (an attached email) from the message. Indexing begins at 0. This example attaches an email, removes it, and prints the attached-message count before and after.
Background: Attached messages (forwarded emails carried as
message/rfc822 parts) are counted and indexed separately from ordinary file attachments and related items. RemoveAttachedMessage targets just one nested email by index — useful, for example, when trimming a bundled digest or stripping a forwarded original before re-sending.Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// Demonstrates the RemoveAttachedMessage method, which removes the Nth message/rfc822
// sub-part (attached email) of the email. The index is zero-based.
// Build an inner email and attach it to an outer email.
final innerEmail = CkEmail();
innerEmail.subject = 'Embedded message';
innerEmail.from = 'alice@example.com';
final email = CkEmail();
email.subject = 'Has an attached message';
try {
email.attachEmail(innerEmail);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
print('NumAttachedMessages before = ${email.numAttachedMessages}');
// Remove the first attached message (index 0).
email.removeAttachedMessage(0);
print('NumAttachedMessages after = ${email.numAttachedMessages}');
}