Dart
Dart
Save Email Attachments to Filesystem
Saves email attachments to a directory.Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
final email = CkEmail();
// Load an email object containing attachments.
// This .eml can be downloaded from:
// http://www.example-code.com/testData/HtmlEmail.eml
try {
email.loadEml('HtmlEmail.eml');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// If OverwriteExisting is turned on, files with the same
// name are overwritten. If turned off, new/unique filenames
// are automatically generated. The filenames actually saved
// are accessible via the GetAttachmentFilename method.
email.overwriteExisting = true;
// Save all attachments to the "myAttachments" subdirectory
// found under the calling process's current working directory.
// This directory is automatically created if it does not already
// exist.
try {
email.saveAllAttachments('myAttachments');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// List the attachment filenames:
for (var i = 0; i < email.numAttachments; i++) {
print(email.getAttachmentFilename(i));
}
}