Dart
Dart
Add File Attachments to an Email
Demonstrates how to add one or more file attachments to an email.Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
final email = CkEmail();
email.subject = 'This is a test';
email.body = 'This is a test';
email.from = 'support@chilkatsoft.com';
email.addTo('Chilkat Admin', 'admin@chilkatsoft.com');
// To add file attachments to an email, call AddFileAttachment
// once for each file to be attached. The method returns
// the content-type of the attachment if successful, otherwise
// returns cknull
var contentType = '';
try {
contentType = email.addFileAttachment('something.pdf');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
try {
contentType = email.addFileAttachment('something.xml');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
try {
contentType = email.addFileAttachment('something.zip');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
try {
email.saveEml('email.eml');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
print('Saved EML!');
}