attach method

  1. @override
MailerInterface attach(
  1. String path, {
  2. String? name,
  3. String? mimeType,
})
override

Attaches a file to the email.

path is the file path on disk. name is the optional display name for the attachment. mimeType is the optional MIME type.

Implementation

@override
MailerInterface attach(String path, {String? name, String? mimeType}) {
  final file = File(path);
  if (!file.existsSync()) {
    throw MailException('Attachment file not found: $path');
  }

  _message.addAttachment(
    MailAttachment(
      path: path,
      filename: name ?? file.uri.pathSegments.last,
      mimeType: mimeType,
    ),
  );
  return this;
}