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

Create, save, and reopen a plain-text email

See more Email Object Examples

Set the sender, recipient, subject, and plain-text body. Save the result as an EML file, then open it in a second Email object and read its contents.

Chilkat Dart Downloads

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

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

  final email = CkEmail();
  email.from = 'Sam Lee <sam@example.com>';
  try {
    email.addTo('Alex Rivera', 'alex@example.net');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  email.subject = 'Hello';
  email.body = 'This is a plain-text message.';
  try {
    email.saveEml('message.eml');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  final received = CkEmail();
  try {
    received.loadEml('message.eml');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  print(received.from);
  print(received.subject);
  print(received.getPlainTextBody());
}