EmailAttachment.fromFile constructor

EmailAttachment.fromFile(
  1. File file, {
  2. String? customName,
})

Creates an attachment by reading the contents of a File.

When customName is omitted, the filename is derived from the file path.

Example:

final attachment = EmailAttachment.fromFile(
  File('/tmp/report.pdf'),
);

Implementation

EmailAttachment.fromFile(File file, {String? customName})
  : name = customName ?? file.path.split('/').last,
    content = file.readAsBytesSync(),
    contentType = _getContentType(file.path);