Sample code for 30+ languages & platforms
Dart Requires Chilkat v11.0.0+

Read an attached email

See more Email Object Examples

Open forward-as-attachment.eml from the forwarding example. Read the cover note’s subject, then open each attached message and inspect its own headers and attachment count. This works even when the outer message has no ordinary files.

Chilkat Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

void main() {
  // Assumes Chilkat is unlocked. See Global Unlock Sample.

  final wrapper = CkEmail();
  try {
    wrapper.loadEml('forward-as-attachment.eml');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  print('Cover note: ${wrapper.subject}');
  if (wrapper.numAttachedMessages == 0) {
    print('No attached messages.');
    return;
  }

  final nested = CkEmail();
  var i = 0;
  while (i < wrapper.numAttachedMessages) {
    try {
      wrapper.getAttachedEmail(i, nested);
    } on ChilkatException catch (e) {
      print(e.lastErrorText);
      return;
    }

    print('Original author: ${nested.from}');
    print('Original subject: ${nested.subject}');
    print('Files on the original: ${nested.numAttachments}');
    i++;
  }
}