Dart Requires Chilkat v11.0.0+
Dart
Forward an email as an attachment
See more Email Object Examples
Attach the original Email to a new message as a message/rfc822 part. The recipient can open the attached email and read its original headers and body.
Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// Assumes Chilkat is unlocked. See Global Unlock Sample.
final original = CkEmail();
try {
original.loadEml('message.eml');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
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 = 'Forwarded message';
email.body = 'The original email is attached.';
try {
email.attachEmail(original);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
try {
email.saveEml('forward-as-attachment.eml');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
print('Saved forward-as-attachment.eml.');
}